The Data.Binary
documentation shows writing an instance by hand. Is there a way around this? I saw here there is another library, SerTH, which has a (Template Haskell based) deriving mechanism, but the link to it seems broken. Also, if you know other libraries, good performance is critical for us.
Thank you in advance!
See http://hackage.haskell.org/packages/archive/binary/0.7.1.0/doc/html/Data-Binary.html#g:3
{-# LANGUAGE DeriveGeneric #-}
import Data.Binary
import GHC.Generics (Generic)
data Foo = Foo
deriving (Generic)
-- GHC will automatically fill out the instance
instance Binary Foo
Neil Mitchells Derive package has a template haskell macro for deriving binary instances.
Since you asked about other libraries:
The cereal data serialisation library has cereal-derive, which works with the new Generics support in GHC 7.2. This has a compile-time speed advantage over Template Haskell (I tend to avoid TH these days just because it makes compilation even slower) and a run-time speed advantage over datatype-generic methods like SYB and Uniplate.
cereal is very similar to binary, but uses strict ByteStrings; binary hasn't been updated since 2009 and cereal has niceties such as IEEE-754 float format support, so I can't see any reason not to use it over binary if you want deriving.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With