[EMAIL PROTECTED] (Marcin 'Qrczak' Kowalczyk) 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?
>
> > > 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.
>
> What woyld GtkText* map to? GtkText is a typedef to an opaque struct.
One idea that we discussed is that `GtkText*' would map to
`Ptr GtkText', where `GtkText' is opaque und would indeed be
implemented as
newtype GtkText = GtkText ()
This way, we wouldn't try to model Haskell's type system in
C or the other way around, but just increase type safety by
using types such as `GtkText' as Skolem variables that only
match with themselves in Haskell's type checker. The nice
thing about that would be that, we can have
gtkTextNew :: GtkAdjustment -> GtkAdjustment -> IO (Ptr GtkText)
gtkSetEditable :: (Ptr GtkText) -> Bool -> IO ()
as well as
gListAppend :: Ptr GList -> Ptr a -> Ptr GList
where we ensure type safety so far as we can pass to
`gtkSetEditable' only values produced by `gtkTextNew', but
still the definition of `gListAppend' is polymorphic in its
second argument and can add values of `Ptr GtkList' as well
as other pointer values into a `GList'.[1]
As Sven pointed out, it was suggested that we collect some
experience with this definition before including it into the
FFI standard proposal. The next version of C->HS will
support `Ptr a' to gather some experience with its use.
Cheers,
Manuel
[1] The definition uses `Ptr GList' and not `Ptr (GList a)'
on purpose. `GList's are - unlike Haskell lists -
heterogenous, as this is what the original C library
(`GLib') defines.
PS: This proposal does not address the problem of cross-FFI
type consistency raised by Fergus. It only makes the
Haskell binding of C code more type safe.