[Haskell-cafe] Type safety in foreign pointer

Mauricio briqueabraque at yahoo.com
Wed Oct 15 09:40:16 EDT 2008


Hi,

I'm wrapping a library where functions take
as parameters pointers to a few standard
structs (as, well, all C libraries). I
would like to ensure that only pointers of
correct structs are passed to those functions.
What is the "Haskell way" to do that? My
idea is to do something like this:

newtype SomeStruct = SomeStruct ()

and then

foreign import ccall "my_function" myfunction
   :: Ptr SomeStruct -> IO int

Is that the proper way to do that?

Thanks,
Maurício



More information about the Haskell-Cafe mailing list