ANN: H98 FFI Addendum 1.0, Release Candidate 10

Manuel M T Chakravarty chak at cse.unsw.edu.au
Thu Jun 5 04:04:31 EDT 2003


"Simon Marlow" <simonmar at microsoft.com> wrote,

>  
> > > > >   data Point
> > > > >   foreign import getMousePos :: Ptr Point ->  IO ()
> > > > >   foreign import getX :: Ptr Point -> IO Int
> > > > >   foreign import getY :: Ptr Point -> IO Int
> > 
> > vs
> > 
> > >   data Point = Point (Ptr Point)
> > >   foreign import getMousePos :: Point ->  IO ()
> > 
> > I like the second idiom.  You are right that there is no need for
> > the application programmer to know whether pointers are involved,
> > because even in the first style, it is not possible to 'peek' inside
> > a Ptr Point to get the `actual' Point value.  So why not hide the
> > pointer altogether?  Yes.
> 
> I presume that should be 'newtype' rather than 'data'?

True.

Manuel



More information about the FFI mailing list