bound 0.7 → 0.8
raw patch · 6 files changed
+121/−12 lines, 6 filesdep +binarydep +bytesdep +cerealPVP ok
version bump matches the API change (PVP)
Dependencies added: binary, bytes, cereal
API changes (from Hackage documentation)
+ Bound.Name: instance (Binary b, Binary a) => Binary (Name b a)
+ Bound.Name: instance (Serial b, Serial a) => Serial (Name b a)
+ Bound.Name: instance (Serialize b, Serialize a) => Serialize (Name b a)
+ Bound.Name: instance Serial b => Serial1 (Name b)
+ Bound.Name: instance Serial2 Name
+ Bound.Scope: deserializeScope :: (Serial1 f, MonadGet m) => m b -> m v -> m (Scope b f v)
+ Bound.Scope: instance (Binary b, Serial1 f, Binary a) => Binary (Scope b f a)
+ Bound.Scope: instance (Serial b, Serial1 f) => Serial1 (Scope b f)
+ Bound.Scope: instance (Serial b, Serial1 f, Serial a) => Serial (Scope b f a)
+ Bound.Scope: instance (Serialize b, Serial1 f, Serialize a) => Serialize (Scope b f a)
+ Bound.Scope: serializeScope :: (Serial1 f, MonadPut m) => (b -> m ()) -> (v -> m ()) -> Scope b f v -> m ()
+ Bound.Var: instance (Binary b, Binary a) => Binary (Var b a)
+ Bound.Var: instance (Serial b, Serial a) => Serial (Var b a)
+ Bound.Var: instance (Serialize b, Serialize a) => Serialize (Var b a)
+ Bound.Var: instance Serial b => Serial1 (Var b)
+ Bound.Var: instance Serial2 Var
Files
- CHANGELOG.markdown +4/−0
- bound.cabal +12/−9
- examples/Simple.hs +1/−1
- src/Bound/Name.hs +33/−1
- src/Bound/Scope.hs +32/−0
- src/Bound/Var.hs +39/−1
CHANGELOG.markdown view
@@ -1,3 +1,7 @@+0.8+---+* Added `Serial`, `Binary` and `Serialize` instances for `Scope`.+ 0.7 --- * Added `Hashable`, `Hashable1` and `Hashable2` instances where appropriate for `Name`, `Var` and `Scope`.
bound.cabal view
@@ -1,6 +1,6 @@ name: bound category: Language, Compilers/Interpreters-version: 0.7+version: 0.8 license: BSD3 cabal-version: >= 1.9.2 license-file: LICENSE@@ -63,14 +63,17 @@ Bound.Var build-depends:- base >= 4 && < 5,- bifunctors >= 3 && < 4,- comonad >= 3 && < 4,- hashable >= 1.1 && < 1.3,- hashable-extras >= 0.1 && < 1,- prelude-extras >= 0.3 && < 1,- profunctors >= 3.3 && < 4,- transformers >= 0.2 && < 0.4+ base >= 4 && < 5,+ bifunctors >= 3 && < 4,+ binary >= 0.5 && < 0.8,+ bytes >= 0.4 && < 1,+ cereal >= 0.3.5.2 && < 0.4,+ comonad >= 3 && < 4,+ hashable >= 1.1 && < 1.3,+ hashable-extras >= 0.1 && < 1,+ prelude-extras >= 0.3 && < 1,+ profunctors >= 3.3 && < 4,+ transformers >= 0.2 && < 0.4 ghc-options: -Wall -O2 -fspec-constr -fdicts-cheap -funbox-strict-fields if impl(ghc>=7.4)
examples/Simple.hs view
@@ -1,7 +1,7 @@ module Main where -- this is a simple example where lambdas only bind a single variable at a time--- this directly corre:sponds to the usual de bruijn presentation+-- this directly corresponds to the usual de bruijn presentation import Data.List (elemIndex) import Data.Foldable hiding (notElem)
src/Bound/Name.hs view
@@ -42,13 +42,16 @@ import Bound.Var import Control.Applicative import Control.Comonad-import Control.Monad (liftM)+import Control.Monad (liftM, liftM2) import Data.Foldable import Data.Traversable import Data.Monoid import Data.Bifunctor import Data.Bifoldable+import qualified Data.Binary as Binary+import Data.Binary (Binary) import Data.Bitraversable+import Data.Bytes.Serial #ifdef __GLASGOW_HASKELL__ import Data.Data # if __GLASGOW_HASKELL__ >= 704@@ -58,6 +61,8 @@ import Data.Hashable import Data.Hashable.Extras import Data.Profunctor+import qualified Data.Serialize as Serialize+import Data.Serialize (Serialize) import Prelude.Extras -------------------------------------------------------------------------------@@ -169,6 +174,33 @@ {-# INLINE compare2 #-} instance Show2 Name where showsPrec2 = showsPrec instance Read2 Name where readsPrec2 = readsPrec++instance Serial2 Name where+ serializeWith2 pb pf (Name b a) = pb b >> pf a+ {-# INLINE serializeWith2 #-}++ deserializeWith2 gb gf = liftM2 Name gb gf+ {-# INLINE deserializeWith2 #-}++instance Serial b => Serial1 (Name b) where+ serializeWith = serializeWith2 serialize+ {-# INLINE serializeWith #-}+ deserializeWith = deserializeWith2 deserialize+ {-# INLINE deserializeWith #-}++instance (Serial b, Serial a) => Serial (Name b a) where+ serialize = serializeWith2 serialize serialize+ {-# INLINE serialize #-}+ deserialize = deserializeWith2 deserialize deserialize+ {-# INLINE deserialize #-}++instance (Binary b, Binary a) => Binary (Name b a) where+ put = serializeWith2 Binary.put Binary.put+ get = deserializeWith2 Binary.get Binary.get++instance (Serialize b, Serialize a) => Serialize (Name b a) where+ put = serializeWith2 Serialize.put Serialize.put+ get = deserializeWith2 Serialize.get Serialize.get ------------------------------------------------------------------------------- -- Abstraction
src/Bound/Scope.hs view
@@ -39,6 +39,8 @@ , traverseScope , mapMBound , mapMScope+ , serializeScope+ , deserializeScope ) where import Bound.Class@@ -48,11 +50,18 @@ import Control.Monad.Trans.Class import Data.Bifunctor import Data.Bifoldable+import qualified Data.Binary as Binary+import Data.Binary (Binary) import Data.Bitraversable+import Data.Bytes.Get+import Data.Bytes.Put+import Data.Bytes.Serial import Data.Foldable import Data.Hashable import Data.Hashable.Extras import Data.Monoid+import qualified Data.Serialize as Serialize+import Data.Serialize (Serialize) import Data.Traversable import Prelude.Extras import Prelude hiding (foldr, mapM, mapM_)@@ -347,3 +356,26 @@ mapMScope f g (Scope s) = liftM Scope (mapM (bimapM f (mapM g)) s) {-# INLINE mapMScope #-} +serializeScope :: (Serial1 f, MonadPut m) => (b -> m ()) -> (v -> m ()) -> Scope b f v -> m ()+serializeScope pb pv (Scope body) = serializeWith (serializeWith2 pb $ serializeWith pv) body+{-# INLINE serializeScope #-}++deserializeScope :: (Serial1 f, MonadGet m) => m b -> m v -> m (Scope b f v)+deserializeScope gb gv = liftM Scope $ deserializeWith (deserializeWith2 gb $ deserializeWith gv)+{-# INLINE deserializeScope #-}++instance (Serial b, Serial1 f) => Serial1 (Scope b f) where+ serializeWith = serializeScope serialize+ deserializeWith = deserializeScope deserialize++instance (Serial b, Serial1 f, Serial a) => Serial (Scope b f a) where+ serialize = serializeScope serialize serialize+ deserialize = deserializeScope deserialize deserialize++instance (Binary b, Serial1 f, Binary a) => Binary (Scope b f a) where+ put = serializeScope Binary.put Binary.put+ get = deserializeScope Binary.get Binary.get++instance (Serialize b, Serial1 f, Serialize a) => Serialize (Scope b f a) where+ put = serializeScope Serialize.put Serialize.put+ get = deserializeScope Serialize.get Serialize.get
src/Bound/Var.hs view
@@ -25,7 +25,7 @@ ) where import Control.Applicative-import Control.Monad (ap)+import Control.Monad (liftM, ap) import Data.Foldable import Data.Traversable import Data.Monoid (mempty)@@ -33,7 +33,12 @@ import Data.Hashable.Extras import Data.Bifunctor import Data.Bifoldable+import qualified Data.Binary as Binary+import Data.Binary (Binary) import Data.Bitraversable+import Data.Bytes.Get+import Data.Bytes.Put+import Data.Bytes.Serial #ifdef __GLASGOW_HASKELL__ import Data.Data # if __GLASGOW_HASKELL__ >= 704@@ -41,6 +46,8 @@ # endif #endif import Data.Profunctor+import qualified Data.Serialize as Serialize+import Data.Serialize (Serialize) import Data.Word import Prelude.Extras @@ -80,6 +87,37 @@ hashWithSalt s (B b) = hashWithSalt s b hashWithSalt s (F a) = hashWithSalt s a `hashWithSalt` distinguisher {-# INLINE hashWithSalt #-}++instance Serial2 Var where+ serializeWith2 pb _ (B b) = putWord8 0 >> pb b+ serializeWith2 _ pf (F f) = putWord8 1 >> pf f+ {-# INLINE serializeWith2 #-}++ deserializeWith2 gb gf = getWord8 >>= \b -> case b of+ 0 -> liftM B gb+ 1 -> liftM F gf+ _ -> fail $ "getVar: Unexpected constructor code: " ++ show b+ {-# INLINE deserializeWith2 #-}++instance Serial b => Serial1 (Var b) where+ serializeWith = serializeWith2 serialize+ {-# INLINE serializeWith #-}+ deserializeWith = deserializeWith2 deserialize+ {-# INLINE deserializeWith #-}++instance (Serial b, Serial a) => Serial (Var b a) where+ serialize = serializeWith2 serialize serialize+ {-# INLINE serialize #-}+ deserialize = deserializeWith2 deserialize deserialize+ {-# INLINE deserialize #-}++instance (Binary b, Binary a) => Binary (Var b a) where+ put = serializeWith2 Binary.put Binary.put+ get = deserializeWith2 Binary.get Binary.get++instance (Serialize b, Serialize a) => Serialize (Var b a) where+ put = serializeWith2 Serialize.put Serialize.put+ get = deserializeWith2 Serialize.get Serialize.get unvar :: (b -> r) -> (a -> r) -> Var b a -> r unvar f _ (B b) = f b