>The nhc98 compiler already accepts a `deriving Binary' clause.
>DrIFT likewise already supports {-! derives : Binary !-}. I imagine
>it wouldn't be too difficult to use GHC's support for Generics to code
>up a simple deriving mechanism as well.
What was the strategy employed to derive instances of sum types, i.e. the
binary representation?
_________________________________________________________________
MSN Instant Messenger now available on Australian mobile phones. Go to
http://ninemsn.com.au/mobilecentral/hotmail_messenger.asp
> a recent post reminded me of a feature i'd like.
> for all i know it is already implemenetd in GHC so pointers
> are welcome.
>
> i'd like to be able to dump data structures to disk, and later load
> them.
A Binary library was discussed recently on the libraries list. The
thread starts here:
http://www.haskell.org/pipermail/libraries/2002-November/000691.html
It's currently stalled. There are several implementations of Binary:
one that comes with NHC and is described in a paper (sorry, don't have a
link to hand), a port of this library to GHC by Sven Panne (suffers from
bitrot), a derived/simplified version used in GHC which is heavily
hacked for speed, and a further derived version of this library by Hal
Daume who is adapting it to support bit-by-bit serialisation.
I think the outstanding issues are
(a) is the API for GHC's Binary library acceptable, or do we need
the extra bells and whistles that the NHC version has?
(b) can we make a version of Binary that uses a bit-by-bit
rather than byte-by-byte serialisation of the data that is
as fast (or nearly as fast) as the current byte-by-byte
implementation? Perhaps performance isn't that important
to the majority of people: please comment if you have
an opinion.
(c) how do we derive instances of Binary?
IMHO: something is better than nothing, so I'd be in favour of just
plugging in the Binary library from GHC, and marking it "experimental".
Cheers,
Simon
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(a)haskell.org
> http://www.haskell.org/mailman/listinfo/ffi
--
---------------------------------------------------------------------------
John Meacham - California Institute of Technology, Alum. - john(a)foo.net
---------------------------------------------------------------------------