Cetin Sert
Cetin Sert

Reputation: 4590

How to provide a Data.Vector.Unbox instance for StablePtr's in Haskell?

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?

Upvotes: 1

Views: 229

Answers (1)

dnaq
dnaq

Reputation: 2234

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.

Upvotes: 2

Related Questions