Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Storable which is only Peekable (PICCA Frederic-Emmanuel)


----------------------------------------------------------------------

Message: 1
Date: Sun, 4 Aug 2019 09:57:28 +0000
From: PICCA Frederic-Emmanuel
        <frederic-emmanuel.pi...@synchrotron-soleil.fr>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <beginners@haskell.org>
Subject: [Haskell-beginners] Storable which is only Peekable
Message-ID:
        
<a2a20ec3b8560d408356cac2fc148e53016cf45...@sun-dag3.synchrotron-soleil.fr>
        
Content-Type: text/plain; charset="us-ascii"

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


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 134, Issue 1
*****************************************

Reply via email to