Persistant (as in on disk) data

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

"mike V"
The nhc98 compiler already accepts a `deriving Binary' clause. DrIFT likewise already supports {-! derives : Binary !-}.
What was the strategy employed to derive instances of sum types, i.e. the binary representation?
For a sum-of-products type with n constructors, represent the constructor as a bit sequence of length ceiling(log n), and then simply append the binary representation of each product component. This gives a nice generic scheme, although of course it is possible to write instances manually that yield a higher compression. For instance in some applications we used Huffman encoding based on the frequency of occurrence of each constructor. Regards, Malcolm
participants (2)
-
Malcolm Wallace
-
mike V