packages feed

monad-codec 0.1.1 → 0.2.0

raw patch · 2 files changed

+16/−8 lines, 2 filesdep +binary

Dependencies added: binary

Files

Control/Monad/Codec.hs view
@@ -51,9 +51,10 @@ , idLens ) where -import Control.Applicative (Applicative, (<$>))+import Control.Applicative (Applicative, (<$>), (<*>)) import Data.Lens.Common (Lens, getL, setL, iso)-import qualified Control.Monad.State as S+import Data.Binary (Binary, put, get)+import qualified Control.Monad.State.Strict as S import qualified Data.Map as M import qualified Data.IntMap as I @@ -78,13 +79,17 @@     { to    :: !(M.Map a Int)     , from  :: !(I.IntMap a) } +instance (Ord a, Binary a) => Binary (AtomCodec a) where+    put atom = put (to atom) >> put (from atom)+    get = AtomCodec <$> get <*> get+ -- | Empty codec component. empty :: AtomCodec a empty = AtomCodec M.empty I.empty --- | Update a map with a given element and increase.  If the element--- has not been previously in the map it will be assigned a new--- unique integer number.+-- | Update the map with the given element and increase the counter.  If the+-- element has not been previously in the map it will be assigned a new unique+-- integer number. updateMap :: Ord a => M.Map a Int -> a -> M.Map a Int updateMap mp x =   case M.lookup x mp of@@ -111,7 +116,8 @@         m' = updateMap (to atomCodec) x         y  = m' M.! x         r' = I.insert y x (from atomCodec)-        codec' = setL lens (AtomCodec m' r') codec+        !atom = AtomCodec m' r'+        codec' = setL lens atom codec     setCodec codec'     return y @@ -125,7 +131,8 @@     let atomCodec = getL lens codec         m' = updateMap (to atomCodec) x         y  = m' M.! x-        codec' = setL lens (atomCodec { to = m' }) codec+        !atom = atomCodec { to = m' }+        codec' = setL lens atom  codec     setCodec codec'     return y 
monad-codec.cabal view
@@ -1,5 +1,5 @@ name:               monad-codec-version:            0.1.1+version:            0.2.0 synopsis:           Monadic conversion between complex data structures and unique integers description:     The library provides functions for encoding and decoding complex data@@ -23,6 +23,7 @@       , containers       , data-lens       , mtl >= 2+      , binary      exposed-modules:         Control.Monad.Codec