[Haskell-cafe] question concerning ANSI "void *"

Adam Langley agl at imperialviolet.org
Thu Feb 7 16:30:34 EST 2008

2008/2/7 Galchin Vasili <vigalchin at gmail.com>:
>      Ok .. I am writing a Haskell function that will call down into the ANSI
> C library .. blah :: .... -> Ptr Word8 ....-> .... The underlying C function
> that "blah" is calling has a "void *" so I am using "Ptr Word  8" to model
> the "void *".

Depending on the context, "void *" is generally either taken as a Ptr
() (for an opaque pointer) or Ptr Word8 (for calls like memcpy).

> I propose to have the callers of function "blah" to populate a
> data structure something like "Ptr Buz" where "data Buz = { ........} and
> then do a "recast :: Ptr Word 8 -> Ptr Buz" when invoking function "blah".
> Does this seem reasonable? Is there a better way?

Generally, Ptr x is only used where x is either a shadow type or a
Bits type. Having a Ptr Baz where Baz is an ADT seems a little odd. If
you need to translate a structure from Haskell to C code, probably you
are better off having callers pass in a Baz then, internal to the
wrapping, fill out the C structure and call the FFI function with a
Ptr CBaz (where CBaz is a shadow type).


Adam Langley                                      agl at imperialviolet.org
http://www.imperialviolet.org                       650-283-9641

More information about the Haskell-Cafe mailing list