[Haskell-beginners] Storable which is only Peekable

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Sun Aug 4 09:57:28 UTC 2019


Hello, I would  like to know what is the best way to create a type which is only peekable and pokable.
When I use Storable, I "need" to define peek and poke and ghc complain that I did not defined the poke part.

So how can I write something nice.

Cheers


Frederic


#include "hkl-binoculars.h"

data Space = Space (ForeignPtr Space) Int
  deriving Show

foreign import ccall safe "fromImage" c_fromImage :: Ptr Double -> Int -> Ptr Double -> Ptr Int -> Int -> Ptr Word16 -> Ptr Int -> Int -> IO (Ptr Space)
foreign import ccall unsafe "&space_free" c_space_free :: FunPtr (Ptr Space -> IO ())

instance Storable Space where
  alignment _ = #{alignment struct space_t}
  sizeOf _ = #{size struct space_t}
  peek ptr = Space
             <$> newForeignPtr c_space_free ptr
             <*> #{peek struct space_t, ndim} ptr


More information about the Beginners mailing list