Home

Awesome

Build Status

Hackage version

Stackage LTS 16 Stackage LTS 18 Stackage LTS 19 Stackage Nightly

Haskell implementation of Flat, a principled, portable and compact binary data format (specs).

How To Use It For Fun and Profit

{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
import Flat
data Direction = North | South | Center | East | West deriving (Show,Generic,Flat)

Use flat to encode:

flat [North,South]
-> "\149"

and unflat to decode:

unflat (flat [North,South]) :: Decoded [Direction]
-> Right [ North , South ]

And thanks to Flat's bit-encoding, this list fits in 1 byte (rather than the 5 bytes that would be required by a traditional byte encoding):

flatBits [North,South]
-> "10010101"

Performance

For some hard data, see this comparison of the major haskell serialisation libraries.

Briefly:

Documentation

Installation

Get the latest stable version from hackage.

Compatibility

Tested with:

Known Bugs and Infelicities

Ports for other languages

Rust and TypeScript-JavaScript ports are under development.

Get in touch if you would like to help porting flat to other languages.

Acknowledgements

flat reuses ideas and readapts code from various packages, mainly: store, binary-bits and binary and includes bug fixes from a number of contributors.

Other Stuff You Might Like

To decode flat encoded data you need to know the type of the serialised data.

This is ok for applications that do not require long-term storage and that do not operate in open distributed systems.

For those who do, you might want to supplement flat with ZM - Language independent, reproducible, absolute types.