[Haskell-cafe] [Haskell] ANNOUNCE: system-filepath 0.4.5 and system-fileio 0.3.4

John Meacham john at repetae.net
Thu Feb 9 20:40:28 CET 2012


On Thu, Feb 9, 2012 at 11:23 AM, Ian Lynagh <igloo at earth.li> wrote:
> On Thu, Feb 09, 2012 at 04:52:16AM -0800, John Meacham wrote:
>>
>> Since CSigSet has "sigset_t" associated with it, 'Ptr CSigSet' ends up turning
>> into 'sigset_t *' in the generated code. (Ptr (Ptr CChar)) turns into char**
>> and so forth.
>
> What does the syntax for associating sigset_t with CSigSet look like?

There currently isn't a user accessable once, but CSigSet is included in the
FFI spec so having the complier know about it isn't that bad. In fact, it is
how I interpreted the standard. Otherwise, why would CFile be specified if it
didn't expand 'Ptr CFile' properly. I just have a single list of associations
that is easy to update at the moment, but a user defineable way is something i
want in the future. My current syntax idea is.

data CFile = foreign "stdio.h FILE"

but it doesn't extend easily to 'newtype's
or maybe a {-# CTYPE "FILE" #-} pragma...

The 'Ptr' trick is useful for more than just pointers, I use the same thing to
support native complex numbers. I have

data Complex_ :: # -> #  -- type function of unboxed types to unboxed types.

then can do things like 'Complex_ Float64_' to get hardware supported complex
doubles. The expansion happens just like 'Ptr' except instead of postpending
'*' when it encounters _Complex, it prepends '_Complex ' (a C99 standard
keyword).

You can then import primitives like normal (for jhc)

foreign import primitive "Add" complexPlus ::
        Complex_ Float64_ -> Complex_ Float64_ -> Complex_ Float64_

and lift it into a data type and add instances for the standard numeric classes
if you wish. (I have macros that automate the somewhat repetitive instance
creation in lib/jhc/Jhc/Num.m4)

        John



More information about the Haskell-Cafe mailing list