On 28-Mar-2000, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> wrote:
> Tue, 28 Mar 2000 12:26:34 +1000, Fergus Henderson <[EMAIL PROTECTED]> pisze:
>
> > It would be fine to have a `typedef void *HsStablePtr'. But it is important
> > that you do not lose static type information when exporting Haskell functions
> > to C. So a parameter of type `StablePtr Int' on the Haskell side should get
> > converted to a pointer to an opaque struct type, e.g. `struct HsStablePtrInt *'
> > in C, not to just plain `HsStablePtr'.
>
> What would StablePtr (b -> [Maybe Int] -> IO (Integer, b)) map to?
For type constructors like `->', `[]', and `Maybe', which (unlike StablePtr)
don't have any C equivalent, I think you probably need to drop the structure,
and just keep the top-level type constructor, thus mapping that type to just
`struct HsStablePtrFunc *'.
It would be nice if more of the structure could be preserved, but I don't see
any way to do that in C mangling the Haskell type names into C identifiers,
which would make it exceedingly cumbersome to use, and I think would also
break the Haskell substitutability properties anyway.
Still, just making sure that Haskell types with distinct top-level type
constructors get mapped to distinct C types is probably enough to catch
most of the type errors.
> > > BTW, Ptr is probably not fully polymorphic, e.g.
> > > what should be the mapping for
> > >
> > > Ptr (b -> [Maybe Int] -> IO (Integer, b))
> > > ?
> >
> > It should be a pointer to whatever the mapping for
> > `b -> [Maybe Int] -> IO (Integer, b)' is.
>
> There is no mapping for the latter type.
Then there should be no mapping for the former type either.
But I don't see why that means that Ptr is not fully polymorphic;
it just means that not all instances of `Ptr t' have corresponding
types in C.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.