haskell / haskell/primitive

Document why we can't derive Prim instances from Storable ones, and do what we can

Open
#207 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Haskell
Stars
123
Forks
60
PR merge metrics
No merged PRs in 30d

Description

We have `PrimStorable` to derive `Storable` instances from `Prim` instances. It would be very nice to be able to offer a `StorablePrim` to go the other way. Unfortunately, I don't think it's quite possible to do this.

The tricky parts are the `ByteArray#` and `MutableByteArray#` operations. We can *almost* use `byteArrayContents# :: ByteArray# -> Addr#`, but that only works reliably if the `ByteArray#` is pinned. The trouble is that the garbage collector could run between the time we get the address of the start of the array and the time the appropriate `Storable` method uses it. I'm pretty sure the only entirely reliable way to implement these operations would be to copy the entire array, which is just awful.

On the other hand, we *can* offer adapter functions for all the other `Prim` methods, so I think we should add them.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.