Comparing [Fun]Ptrs

Manuel M T Chakravarty chak at cse.unsw.edu.au
Wed Mar 5 11:44:38 EST 2003


Volker Stolz <vs at foldr.org> wrote,

> Hi, I'm looking for a way of comparing Ptrs to null *elegantly*.
> The FFI distinguishes between 'Ptr a' and 'FunPtr a', so testing
> would mean writing ((==) null[Fun]Ptr). This is rather tedious and a predicate
> 'isNull' might be in order so that it's possible to write
> 
>    when (isNull p) $ ...
> or
>    throwIOErrorIf isNull ...
> , especially without having to worry about comparing against the correct
> null pointer (FunPtr or Ptr). That's something where a class can help, but
> I'm not sure whether such a specialised class is desired...

An isNullPtr was proposed before and rejected; see the
corresponding thread in the archive of this list.  Mainly on
the grounds that people didn't consider ((==) null[Fun]Ptr)
to be tedious to write.

Besides, I really don't want to make any changes for version
1.0 of the spec anymore; except finish up the
finalizer/Foreign{Ptr,Proxy} story.  Further convenience
functions can go into extra libraries (there is no need to
stick them all in the base spec).

Cheers,
Manuel



More information about the FFI mailing list