Skip to content

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

Open
@treeowl

Description

@treeowl

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions