About
Data.Binary is a library for high performance binary serialisation
of Haskell data. It uses the
ByteString library to achieve efficient, lazy reading and
writing of structures in binary format.
Example
For example, to serialise an interpreter's abstract syntax tree to
binary format:
import Data.Binary
import Control.Monad
import Codec.Compression.GZip
data Exp = IntE Int
| OpE String Exp Exp
deriving Eq
instance Binary Exp where
put (IntE i) = put (0 :: Word8) >> put i
put (OpE s e1 e2) = put (1 :: Word8) >> put s >> put e1 >> put e2
get = do tag <- getWord8
case tag of
0 -> liftM IntE get
1 -> liftM3 OpE get get get
e = OpE "*" (IntE 7) (OpE "/" (IntE 4) (IntE 2))
main = do
let t = compress (encode e)
print t
let e' = decode (decompress t)
print (e == e')
Download
stable release
|
development branch
|
Download
Project Activity
Starring...
The Binary Strike Force
- Lennart Kolmodin
- Duncan Coutts
- Don Stewart
- Spencer Janssen
- David Himmelstrup
- Björn Bringert
- Ross Paterson
- Einar Karttunen
- John Meacham
- Ulf Norell
- Bryan O'Sullivan
- Tomasz Zielonka
- Florian Weimer
- Judah Jacobson
|