qforeign-0.62
Marcin 'Qrczak' Kowalczyk
mk167280 at students.mimuw.edu.pl
Fri Dec 1 05:50:07 EST 2000
On Fri, 1 Dec 2000, Simon Peyton-Jones wrote:
> if it's really so, we woudn't need the objectionable
>
> > withForeignObj :: ForeignObj -> (Ptr a -> IO b) -> IO b
>
> because all ForeignObj-manipulating things would be foreign
> imported
>
> foreign import f :: Window -> IO ()
It's not always that foreign objects are abstract from the Haskell's point
of view. Often, but not always.
There is a large intermediate area, where foreign objects store structures
which don't have a Haskell equivalent to put in the argument of the
ForeignObj type, but programs refer to their fields directly. hsc2hs
provides a way to access those fields:
withForeignObj obj $ \ptr -> do
x <- (#peek struct foo, field1) ptr
y <- (#peek struct foo, field2) ptr
...
I am not strongly arguing for either option (ForeignObj or ForeignObj a).
Both are OK. Beware that in case of ForeignObj a the type will often be
tagged with a void type or () - neither will be used as the argument
of the corresponding Ptr in a useful way (neither is Storable).
--
Marcin 'Qrczak' Kowalczyk
More information about the FFI
mailing list