monad-atom 0.1.0 → 0.1.1
raw patch · 2 files changed
+10/−6 lines, 2 files
Files
- Control/Monad/Atom.hs +9/−5
- monad-atom.cabal +1/−1
Control/Monad/Atom.hs view
@@ -18,9 +18,10 @@ import qualified Data.Map as Map import qualified Data.IntMap as IntMap import qualified Data.Binary as B-import qualified Data.ByteString.Lazy as BS+import qualified Data.ByteString as Strict+import qualified Data.ByteString.Lazy as Lazy -type Blob = BS.ByteString+type Blob = Strict.ByteString data AtomTable = T { lastID :: {-# UNPACK #-} !Int , to :: Map.Map Blob Int @@ -48,7 +49,7 @@ instance Monad m => MonadAtom (AtomT m) where toAtom x = AtomT $ do- let b = B.encode x+ let b = enc x t <- get case Map.lookup b (to t) of Just j -> return $! j@@ -64,11 +65,11 @@ maybeToAtom x = AtomT $ do t <- get- return . Map.lookup (B.encode x) . to $ t+ return . Map.lookup (enc x) . to $ t fromAtom i = AtomT $ do t <- get- return . B.decode $ (from t) IntMap.! i+ return . dec $ (from t) IntMap.! i table = AtomT get @@ -93,6 +94,9 @@ newtype Atom r = Atom (AtomT Identity r) deriving (Functor,Monad,MonadAtom)++enc = Strict.concat . Lazy.toChunks . B.encode+dec = B.decode . Lazy.fromChunks . return example :: [String] example = evalAtom $ do
monad-atom.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.1.0+Version: 0.1.1 -- A short (one-line) description of the package. Synopsis: Monadically convert objects to unique atoms and back.