문제

I want to use the vector package to store unboxed arrays of StablePtr a

How can I use the following (or variations thereof):

ptr2Int :: Ptr a -> Int
ptr2Int (Ptr a) = I# (addr2Int# a)

stablePtrToInt :: StablePtr a -> Int
stablePtrToInt = ptr2Int . castStablePtrToPtr

intToStablePtr :: Int -> StablePtr a
intToStablePtr (I# i) = castPtrToStablePtr $ Ptr (int2Addr# i)

to declare an Unbox instance for StablePtr a?

도움이 되었습니까?

해결책

There's actually no need trying to define an Unbox instance for StablePtr. Since StablePtr's are instances of Storable you can just use Data.Vector.Storable instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top