Type safety in foreign pointer

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

Hello Mauricio, Wednesday, October 15, 2008, 5:40:16 PM, you wrote:
newtype SomeStruct = SomeStruct ()
data SomeStruct = SomeStruct looks even simpler. you don't need to shell around () since you anyway will not use its value :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Thu, Oct 16, 2008 at 12:53 AM, Bulat Ziganshin
data SomeStruct = SomeStruct
You can even go one step further and do data SomeStruct which will prevent you from accidentally trying to the dummy constructor. However, you'll need {-# LANGUAGE EmptyDataDecls #-} or the equivalent compiler flag to make it work, since it's not Haskell 98 syntax. Stuart
participants (3)
-
Bulat Ziganshin
-
Mauricio
-
Stuart Cook