
this is actually something similar to what I was thinking about the other day, we have lots of classes which allow generically CREATING empty values: Monad: fail MonadPlus: mzero Monoid: mempty but no class which allows generic examination of types with empty values how about something like class Empty a where isEmpty :: a -> Bool or perhaps 'Void' instead of 'Empty'... there are probably lots of types which can usefully be made instances of Empty... Maybe, *Ptr, [], Bool, Either, many combinator type libraries such as pretty printers... perhaps this should be added alongside Monoid? also, does Monad, MonadPlus and Monoid seem like they can be cleaned up some? it seems that they should be able to share their common form somehow... perhaps not... John On Tue, Mar 04, 2003 at 11:35:16AM +0100, Volker Stolz 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...
I'd like to add the following class and instances/functions to Foreign.Ptr if nobody objects, they'd make code much more readable and concise:
class ToPtr a where toPtr :: a -> Ptr b
isNull :: ToPtr a => a -> Bool isNull = (==) nullPtr . toPtr
The ToPtr class was suggested my Simon M. in favour of an even more specialised class PtrCmp which just has nullPtr :: PtrCmp a => isNull a -> Bool. -- Volker Stolz * http://www-i2.informatik.rwth-aachen.de/stolz/ * PGP * S/MIME _______________________________________________ FFI mailing list FFI@haskell.org http://www.haskell.org/mailman/listinfo/ffi
-- --------------------------------------------------------------------------- John Meacham - California Institute of Technology, Alum. - john@foo.net ---------------------------------------------------------------------------
participants (1)
-
John Meacham