Manuel M. T. Chakravarty
chak at cse.unsw.edu.au
Fri Dec 1 03:32:52 EST 2000
qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) wrote,
> Fri, 01 Dec 2000 13:10:43 +1100, Manuel M. T. Chakravarty <chak at cse.unsw.edu.au> pisze:
> > Instead of the
> > newtype Window = Window ForeignObj
> > way of wrapping foreign ADTs that we used so far, should we
> > use
> > newtype WindowTag = WindowTag ()
> > type Window = ForeignObj WindowTag
> > ?
> This exposes the fact that Window is a ForeignObj. Ok, but maybe some
> people want it to be more abstract - clients need not to know that
> it's just a ForeignObj. Such type is usually exported.
I don't want to exclude that you write
newtype WindowTag = WindowTag ()
newtype Window = ForeignObj WindowTag
That's fine, too. It would still make
withForeignPtr :: ForeignObj a -> (Ptr a -> IO b) -> IO b
nicer, because it constrains the parameter of `Ptr'.
> BTW, IMHO it's more natural to write
> data WindowTag = WindowTag
> and it would be yet more natural (and would avoid ghc's warning about
> a constructor which is never used) if we were allowed to write
> data WindowTag
> to create a void type.
I agree, but that would be an extension to Haskell and so is
not an option right now. We have to work with what we got.
More information about the FFI