binary 0.4.1 → 0.4.2
raw patch · 6 files changed
+194/−16 lines, 6 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Data.Binary.Get: instance Applicative Get
+ Data.Binary.Put: instance Applicative PutM
Files
- binary.cabal +14/−7
- index.html +149/−0
- src/Data/Binary.hs +6/−7
- src/Data/Binary/Get.hs +11/−1
- src/Data/Binary/Put.hs +13/−0
- tests/Makefile +1/−1
binary.cabal view
@@ -1,32 +1,33 @@ name: binary-version: 0.4.1+version: 0.4.2 license: BSD3 license-file: LICENSE author: Lennart Kolmodin <kolmodin@dtek.chalmers.se> maintainer: Lennart Kolmodin, Don Stewart <dons@galois.com>-homepage: http://www.cse.unsw.edu.au/~dons/binary.html+homepage: http://code.haskell.org/binary/ description: Efficient, pure binary serialisation using lazy ByteStrings.- Haskell values may be encoded to and form binary formats, + Haskell values may be encoded to and from binary formats, written to disk as binary, or sent over the network. Serialisation speeds of over 1 G\/sec have been observed, so this library should be suitable for high performance scenarios.-synopsis: Binary serialization for Haskell values using lazy ByteStrings+synopsis: Binary serialisation for Haskell values using lazy ByteStrings category: Data, Parsing stability: provisional build-type: Simple cabal-version: >= 1.2 tested-with: GHC ==6.4.2, GHC ==6.6.1, GHC ==6.8.0-extra-source-files: README +extra-source-files: README index.html flag bytestring-in-base flag split-base+flag applicative-in-base library if flag(bytestring-in-base) -- bytestring was in base-2.0 and 2.1.1 build-depends: base >= 2.0 && < 2.2- ghc-options: -DBYTESTRING_IN_BASE+ cpp-options: -DBYTESTRING_IN_BASE else -- in base 1.0 and 3.0 bytestring is a separate package build-depends: base < 2.0 || >= 3, bytestring >= 0.9@@ -36,6 +37,12 @@ else build-depends: base < 3.0 + if flag(applicative-in-base)+ build-depends: base >= 2.0+ cpp-options: -DAPPLICATIVE_IN_BASE+ else+ build-depends: base < 2.0+ exposed-modules: Data.Binary, Data.Binary.Put, Data.Binary.Get,@@ -44,4 +51,4 @@ hs-source-dirs: src ghc-options: -O2 -Wall -fliberate-case-threshold=1000 if impl(ghc < 6.5)- ghc-options: -fallow-undecidable-instances+ cpp-options: -fallow-undecidable-instances
+ index.html view
@@ -0,0 +1,149 @@+<?xml version="1.0" encoding="iso-8859-1"?>+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">++<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">+<head>+ <title>Data.Binary - efficient, pure binary serialisation for Haskell</title>+ <link rel="stylesheet" href="http://www.cse.unsw.edu.au/~dons/main.css" type="text/css" />+</head>++<body xml:lang="en" lang="en">++ <div id="content">++ <h2>Data.Binary</h2>++<table width="80%" align="center"> <tr><td>++ <h3>About</h3>+ <p>+ Data.Binary is a library for high performance binary serialisation+ of <a href="http://haskell.org">Haskell</a> data. It uses the+ <a href="http://www.cse.unsw.edu.au/~dons/fps.html"+ >ByteString</a> library to achieve efficient, lazy reading and+ writing of structures in binary format.+ </p>++ <h3>Example</h3>+ For example, to serialise an interpreter's abstract syntax tree to+ binary format:+<pre><span class='keyword'>import</span> <span class='conid'>Data</span><span class='varop'>.</span><span class='conid'>Binary</span>+<span class='keyword'>import</span> <span class='conid'>Control</span><span class='varop'>.</span><span class='conid'>Monad</span>+<span class='keyword'>import</span> <span class='conid'>Codec</span><span class='varop'>.</span><span class='conid'>Compression</span><span class='varop'>.</span><span class='conid'>GZip</span>++<span class='comment'>-- A Haskell AST structure</span>+<span class='keyword'>data</span> <span class='conid'>Exp</span> <span class='keyglyph'>=</span> <span class='conid'>IntE</span> <span class='conid'>Int</span>+ <span class='keyglyph'>|</span> <span class='conid'>OpE</span> <span class='conid'>String</span> <span class='conid'>Exp</span> <span class='conid'>Exp</span>+ <span class='keyword'>deriving</span> <span class='conid'>Eq</span>++<span class='comment'>-- An instance of Binary to encode and decode an Exp in binary</span>+<span class='keyword'>instance</span> <span class='conid'>Binary</span> <span class='conid'>Exp</span> <span class='keyword'>where</span>+ <span class='varid'>put</span> <span class='layout'>(</span><span class='conid'>IntE</span> <span class='varid'>i</span><span class='layout'>)</span> <span class='keyglyph'>=</span> <span class='varid'>put</span> <span class='layout'>(</span><span class='num'>0</span> <span class='keyglyph'>::</span> <span class='conid'>Word8</span><span class='layout'>)</span> <span class='varop'>>></span> <span class='varid'>put</span> <span class='varid'>i</span>+ <span class='varid'>put</span> <span class='layout'>(</span><span class='conid'>OpE</span> <span class='varid'>s</span> <span class='varid'>e1</span> <span class='varid'>e2</span><span class='layout'>)</span> <span class='keyglyph'>=</span> <span class='varid'>put</span> <span class='layout'>(</span><span class='num'>1</span> <span class='keyglyph'>::</span> <span class='conid'>Word8</span><span class='layout'>)</span> <span class='varop'>>></span> <span class='varid'>put</span> <span class='varid'>s</span> <span class='varop'>>></span> <span class='varid'>put</span> <span class='varid'>e1</span> <span class='varop'>>></span> <span class='varid'>put</span> <span class='varid'>e2</span>+ <span class='varid'>get</span> <span class='keyglyph'>=</span> <span class='keyword'>do</span> <span class='varid'>tag</span> <span class='keyglyph'><-</span> <span class='varid'>getWord8</span>+ <span class='keyword'>case</span> <span class='varid'>tag</span> <span class='keyword'>of</span>+ <span class='num'>0</span> <span class='keyglyph'>-></span> <span class='varid'>liftM</span> <span class='conid'>IntE</span> <span class='varid'>get</span>+ <span class='num'>1</span> <span class='keyglyph'>-></span> <span class='varid'>liftM3</span> <span class='conid'>OpE</span> <span class='varid'>get</span> <span class='varid'>get</span> <span class='varid'>get</span>++<span class='comment'>-- A test expression</span>+<span class='varid'>e</span> <span class='keyglyph'>=</span> <span class='conid'>OpE</span> <span class='str'>"*"</span> <span class='layout'>(</span><span class='conid'>IntE</span> <span class='num'>7</span><span class='layout'>)</span> <span class='layout'>(</span><span class='conid'>OpE</span> <span class='str'>"/"</span> <span class='layout'>(</span><span class='conid'>IntE</span> <span class='num'>4</span><span class='layout'>)</span> <span class='layout'>(</span><span class='conid'>IntE</span> <span class='num'>2</span><span class='layout'>)</span><span class='layout'>)</span>++<span class='comment'>-- Serialise and compress with gzip, then decompress and deserialise</span>+<span class='varid'>main</span> <span class='keyglyph'>=</span> <span class='keyword'>do</span>+ <span class='keyword'>let</span> <span class='varid'>t</span> <span class='keyglyph'>=</span> <span class='varid'>compress</span> <span class='layout'>(</span><span class='varid'>encode</span> <span class='varid'>e</span><span class='layout'>)</span>+ <span class='varid'>print</span> <span class='varid'>t</span>+ <span class='keyword'>let</span> <span class='varid'>e'</span> <span class='keyglyph'>=</span> <span class='varid'>decode</span> <span class='layout'>(</span><span class='varid'>decompress</span> <span class='varid'>t</span><span class='layout'>)</span>+ <span class='varid'>print</span> <span class='layout'>(</span><span class='varid'>e</span> <span class='varop'>==</span> <span class='varid'>e'</span><span class='layout'>)</span>+</pre>++ <h3>Download</h3>++ <table width="100%"><tr valign="top">+ <td><h4>stable release</h4>+ <table>+ <tr><td>+ <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-0.4.2"+ >binary 0.4.2</a> + </td><td>(Apr 2008)</td></tr>++ <tr><td>+ <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-0.4.1"+ >binary 0.4.1</a> + </td><td>(Oct 2007)</td></tr>++ <tr><td>+ <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-0.4"+ >binary 0.4</a> + </td><td>(Oct 2007)</td></tr>++ <tr><td>+ <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-0.3"+ >binary 0.3</a> + </td><td>(Mar 2007)</td></tr>++ <tr><td>+ <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/binary-0.3"+ >binary 0.2</a> + </td><td>(Jan 2007)</td></tr>++ </table> + </td>+ <td><h4>development branch</h4>+ <table>+ <tr><td>+ darcs get <a href="http://code.haskell.org/binary"+ >http://code.haskell.org/binary</a>+ </td></tr>+ </table>+ </td> </tr> </table>++ <h3>Download</h3>+ <ul>+ <li>+ <a href="http://hackage.haskell.org/packages/archive/binary/0.4.1/doc/html/Data-Binary.html">Documentation</a>+ </li>+ </ul>++ <h3>Project Activity</h3>++ <center>+ <img src="http://www.cse.unsw.edu.au/~dons/images/commits/community/binary-commits.png"+ alt="binary commit statistics" />+ </center>++ <h3>Starring...</h3>++ The Binary Strike Force+ <ul>+ <li>Lennart Kolmodin </li>+ <li>Duncan Coutts </li>+ <li>Don Stewart </li>+ <li>Spencer Janssen </li>+ <li>David Himmelstrup </li>+ <li>Björn Bringert </li>+ <li>Ross Paterson </li>+ <li>Einar Karttunen </li>+ <li>John Meacham </li>+ <li>Ulf Norell </li>+ <li>Bryan O'Sullivan </li>+ <li>Tomasz Zielonka </li>+ <li>Florian Weimer </li>+ <li>Judah Jacobson </li>+ </ul>++</td></tr> </table>++<img src="http://xmonad.org/images/HPC.badge.jpg" alt="covered by HPC" />+<img src="http://xmonad.org/images/cabal.png" alt="built with Cabal" />+<img src="http://xmonad.org/images/quickcheck.png" alt="tested with QuickCheck" />++ </div>+++ <div id="footer">+Mon Apr 21 16:12:09 PDT 2008+ </div>++</body>+</html>
src/Data/Binary.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE CPP, FlexibleInstances #-}+{-# LANGUAGE CPP, FlexibleInstances, FlexibleContexts #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Binary@@ -88,6 +88,7 @@ -- #if __GLASGOW_HASKELL__ >= 606 import qualified Data.Sequence as Seq+import qualified Data.Foldable as Fold #endif ------------------------------------------------------------------------@@ -104,9 +105,10 @@ -- -- Instances of Binary should satisfy the following property: ----- > get . put == id+-- > decode . encode == id ----- A range of instances are provided for basic Haskell types. +-- That is, the 'get' and 'put' methods should be the inverse of each+-- other. A range of instances are provided for basic Haskell types. -- class Binary t where -- | Encode a value in the Put monad.@@ -638,10 +640,7 @@ instance (Binary e) => Binary (Seq.Seq e) where -- any better way to do this?- put s = put . flip unfoldr s $ \sq ->- case Seq.viewl sq of- Seq.EmptyL -> Nothing- (Seq.:<) e sq' -> Just (e,sq')+ put = put . Fold.toList get = fmap Seq.fromList get #endif
src/Data/Binary/Get.hs view
@@ -69,7 +69,7 @@ ) where -import Control.Monad (when,liftM)+import Control.Monad (when,liftM,ap) import Control.Monad.Fix import Data.Maybe (isNothing) @@ -83,6 +83,10 @@ import qualified Data.ByteString.Lazy.Internal as L #endif +#ifdef APPLICATIVE_IN_BASE+import Control.Applicative (Applicative(..))+#endif+ import Foreign -- used by splitAtST@@ -106,6 +110,12 @@ instance Functor Get where fmap f m = Get (\s -> let (a, s') = unGet m s in (f a, s'))++#ifdef APPLICATIVE_IN_BASE+instance Applicative Get where+ pure = return+ (<*>) = ap+#endif instance Monad Get where return a = Get (\s -> (a, s))
src/Data/Binary/Put.hs view
@@ -52,6 +52,11 @@ import qualified Data.ByteString as S import qualified Data.ByteString.Lazy as L +#ifdef APPLICATIVE_IN_BASE+import Control.Applicative+#endif++ ------------------------------------------------------------------------ -- | The PutM type. A Writer monad over the efficient Builder monoid.@@ -63,6 +68,14 @@ instance Functor PutM where fmap f m = Put (let (a, w) = unPut m in (f a, w))++#ifdef APPLICATIVE_IN_BASE+instance Applicative PutM where+ pure = return+ m <*> k = Put (let (f, w) = unPut m+ (x, w') = unPut k+ in (f x, w `B.append` w'))+#endif instance Monad PutM where return a = Put (a, B.empty)
tests/Makefile view
@@ -4,7 +4,7 @@ runhaskell QC.hs 1000 compiled:- ghc --make -O QC.hs -o qc -no-recomp -threaded+ ghc --make -fhpc -O QC.hs -o qc -no-recomp -threaded time ./qc 500 +RTS -qw -N2 bench:: Benchmark.hs MemBench.hs CBenchmark.o