bound 2 → 2.0.1
raw patch · 10 files changed
+117/−81 lines, 10 filesdep ~deriving-compatdep ~doctestdep ~hashablesetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: deriving-compat, doctest, hashable
API changes (from Hackage documentation)
- Bound.Name: instance (Data.Data.Data b, Data.Data.Data n) => Data.Data.Data (Bound.Name.Name n b)
- Bound.Name: instance (GHC.Read.Read b, GHC.Read.Read n) => GHC.Read.Read (Bound.Name.Name n b)
- Bound.Name: instance (GHC.Show.Show b, GHC.Show.Show n) => GHC.Show.Show (Bound.Name.Name n b)
- Bound.Var: instance (Data.Data.Data a, Data.Data.Data b) => Data.Data.Data (Bound.Var.Var b a)
- Bound.Var: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Bound.Var.Var b a)
- Bound.Var: instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (Bound.Var.Var b a)
- Bound.Var: instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (Bound.Var.Var b a)
- Bound.Var: instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (Bound.Var.Var b a)
+ Bound: infixl 1 >>>=
+ Bound.Class: infixl 1 >>>=
+ Bound.Name: abstractEitherName :: Monad f => (a -> Either b c) -> f a -> Scope (Name a b) f c
+ Bound.Name: instance (Data.Data.Data n, Data.Data.Data b) => Data.Data.Data (Bound.Name.Name n b)
+ Bound.Name: instance (GHC.Read.Read n, GHC.Read.Read b) => GHC.Read.Read (Bound.Name.Name n b)
+ Bound.Name: instance (GHC.Show.Show n, GHC.Show.Show b) => GHC.Show.Show (Bound.Name.Name n b)
+ Bound.Name: instance GHC.Generics.Generic1 (Bound.Name.Name n)
+ Bound.Name: instantiateEitherName :: (Monad f, Comonad n) => (Either b a -> f c) -> Scope (n b) f a -> f c
+ Bound.Scope: abstractEither :: Monad f => (a -> Either b c) -> f a -> Scope b f c
+ Bound.Scope: instance GHC.Base.Functor f => GHC.Generics.Generic1 (Bound.Scope.Scope b f)
+ Bound.Scope: instance GHC.Generics.Generic (Bound.Scope.Scope b f a)
+ Bound.Scope: instantiateEither :: Monad f => (Either b a -> f c) -> Scope b f a -> f c
+ Bound.Scope.Simple: instance Control.DeepSeq.NFData (f (Bound.Var.Var b a)) => Control.DeepSeq.NFData (Bound.Scope.Simple.Scope b f a)
+ Bound.Scope.Simple: instance GHC.Base.Functor f => GHC.Generics.Generic1 (Bound.Scope.Simple.Scope b f)
+ Bound.Scope.Simple: instance GHC.Generics.Generic (Bound.Scope.Simple.Scope b f a)
+ Bound.Var: instance (Data.Data.Data b, Data.Data.Data a) => Data.Data.Data (Bound.Var.Var b a)
+ Bound.Var: instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Bound.Var.Var b a)
+ Bound.Var: instance (GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Bound.Var.Var b a)
+ Bound.Var: instance (GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Bound.Var.Var b a)
+ Bound.Var: instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Bound.Var.Var b a)
+ Bound.Var: instance GHC.Generics.Generic1 (Bound.Var.Var b)
- Bound: class Bound t where m >>>= f = m >>= lift . f
+ Bound: class Bound t
- Bound.Class: class Bound t where m >>>= f = m >>= lift . f
+ Bound.Class: class Bound t
- Bound.Scope.Simple: transverseScope :: (Functor f) => (forall r. g r -> f (h r)) -> Scope b g a -> f (Scope b h a)
+ Bound.Scope.Simple: transverseScope :: Functor f => (forall r. g r -> f (h r)) -> Scope b g a -> f (Scope b h a)
Files
- .travis.yml +1/−1
- CHANGELOG.markdown +7/−0
- Setup.lhs +3/−2
- bound.cabal +4/−3
- src/Bound/Class.hs +3/−5
- src/Bound/Name.hs +26/−19
- src/Bound/Scope.hs +36/−14
- src/Bound/Scope/Simple.hs +22/−10
- src/Bound/TH.hs +2/−2
- src/Bound/Var.hs +13/−25
.travis.yml view
@@ -68,7 +68,7 @@ # any command which exits with a non-zero exit code causes the build to fail. script: - if [ -f configure.ac ]; then autoreconf -i; fi- - rm -rf dist/+ - rm -rf dist/ .ghc.environment.* - cabal sdist # test that a source-distribution can be generated - cd dist/ - SRCTAR=(${PKGNAME}-*.tar.gz)
CHANGELOG.markdown view
@@ -1,3 +1,10 @@+2.0.1+-----+* Add `abstractEither` and `instantiateEither` to `Bound.Scope`, and+ add `abstractEitherName` and `instantiateEitherName` to `Bound.Scope.Name`+* Add `Generic(1)` instances for `Name` and `Scope`+* Support `doctest-0.12`+ 2 - * GHC 8.0 and 8.2 support
Setup.lhs view
@@ -21,7 +21,9 @@ -- -- Probably we are running cabal sdist, when otherwise using new-build -- workflow-import Warning ()+#warning You are configuring this package without cabal-doctest installed. \+ The doctests test-suite will not work as a result. \+ To fix this, install cabal-doctest before configuring. #endif import Distribution.Simple@@ -30,5 +32,4 @@ main = defaultMain #endif- \end{code}
bound.cabal view
@@ -1,6 +1,6 @@ name: bound category: Language, Compilers/Interpreters-version: 2+version: 2.0.1 license: BSD3 cabal-version: >= 1.9.2 license-file: LICENSE@@ -95,7 +95,7 @@ cereal >= 0.3.5.2 && < 0.6, comonad >= 3 && < 6, hashable >= 1.2.5.0 && < 1.3,- mmorph >= 1.0 && < 1.1,+ mmorph >= 1.0 && < 1.2, deepseq >= 1.1 && < 1.5, profunctors >= 3.3 && < 6, template-haskell >= 2.7 && < 3,@@ -169,6 +169,7 @@ ghc-options: -Wall -threaded build-depends: base,- doctest >= 0.11.2 && < 0.12,+ bound,+ doctest >= 0.11.2 && < 0.13, vector >= 0.9 && < 0.13, void
src/Bound/Class.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE CPP #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 704+#if defined(__GLASGOW_HASKELL__) {-# LANGUAGE DefaultSignatures #-} #endif {-# OPTIONS -fno-warn-deprecations #-}@@ -20,10 +20,8 @@ , (=<<<) ) where -#if __GLASGOW_HASKELL__ >= 704 import Control.Monad.Trans.Class-#endif-#if __GLASGOW_HASKELL__ < 710+#if !MIN_VERSION_base(4,8,0) import Data.Monoid #endif import Control.Monad.Trans.Cont@@ -67,7 +65,7 @@ -- -- @m '>>>=' f = m '>>=' 'lift' '.' f@ (>>>=) :: Monad f => t f a -> (a -> f c) -> t f c-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 704+#if defined(__GLASGOW_HASKELL__) default (>>>=) :: (MonadTrans t, Monad f, Monad (t f)) => t f a -> (a -> f c) -> t f c m >>>= f = m >>= lift . f
src/Bound/Name.hs view
@@ -1,16 +1,10 @@ {-# LANGUAGE CPP #-} #ifdef __GLASGOW_HASKELL__ {-# LANGUAGE DeriveDataTypeable #-}--# if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE DeriveGeneric #-}-# endif--#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif -#endif ----------------------------------------------------------------------------- -- | -- Copyright : (C) 2012 Edward Kmett@@ -37,23 +31,23 @@ , name , abstractName , abstract1Name+ , abstractEitherName , instantiateName , instantiate1Name+ , instantiateEitherName ) where import Bound.Scope import Bound.Var-#if __GLASGOW_HASKELL__ < 710+#if !MIN_VERSION_base(4,8,0) import Control.Applicative-#endif-import Control.Comonad-import Control.DeepSeq-import Control.Monad (liftM, liftM2)-#if __GLASGOW_HASKELL__ < 710 import Data.Foldable import Data.Monoid import Data.Traversable #endif+import Control.Comonad+import Control.DeepSeq+import Control.Monad (liftM, liftM2) import Data.Bifunctor import Data.Bifoldable import qualified Data.Binary as Binary@@ -63,9 +57,7 @@ import Data.Functor.Classes #ifdef __GLASGOW_HASKELL__ import Data.Data-# if __GLASGOW_HASKELL__ >= 704 import GHC.Generics-# endif #endif import Data.Hashable (Hashable(..)) import Data.Hashable.Lifted (Hashable1(..), Hashable2(..))@@ -88,10 +80,11 @@ #ifdef __GLASGOW_HASKELL__ , Typeable , Data-# if __GLASGOW_HASKELL__ >= 704 , Generic-# endif+# if __GLASGOW_HASKELL__ >= 706+ , Generic1 #endif+#endif ) -- | Extract the 'name'.@@ -231,9 +224,8 @@ put = serializeWith2 Serialize.put Serialize.put get = deserializeWith2 Serialize.get Serialize.get -# if __GLASGOW_HASKELL__ >= 704-instance (NFData b, NFData a) => NFData (Name b a)-# endif+instance (NFData b, NFData a) => NFData (Name b a) where+ rnf (Name a b) = rnf a `seq` rnf b ------------------------------------------------------------------------------- -- Abstraction@@ -252,6 +244,15 @@ abstract1Name a = abstractName (\b -> if a == b then Just () else Nothing) {-# INLINE abstract1Name #-} +-- | Capture some free variables in an expression to yield+-- a 'Scope' with named bound variables. Optionally change the+-- types of the remaining free variables.+abstractEitherName :: Monad f => (a -> Either b c) -> f a -> Scope (Name a b) f c+abstractEitherName f e = Scope (liftM k e) where+ k y = case f y of+ Left z -> B (Name y z)+ Right y' -> F (return y')+ ------------------------------------------------------------------------------- -- Instantiation -------------------------------------------------------------------------------@@ -270,3 +271,9 @@ instantiate1Name :: Monad f => f a -> Scope n f a -> f a instantiate1Name = instantiate1 {-# INLINE instantiate1Name #-}++instantiateEitherName :: (Monad f, Comonad n) => (Either b a -> f c) -> Scope (n b) f a -> f c+instantiateEitherName k e = unscope e >>= \v -> case v of+ B b -> k (Left (extract b))+ F a -> a >>= k . Right+{-# INLINE instantiateEitherName #-}
src/Bound/Scope.hs view
@@ -6,15 +6,8 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE UndecidableInstances #-}--#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-}-#endif--#endif--#ifndef MIN_VERSION_base-#define MIN_VERSION_base(x,y,z) 1+{-# LANGUAGE DeriveGeneric #-} #endif -----------------------------------------------------------------------------@@ -34,9 +27,9 @@ module Bound.Scope ( Scope(..) -- * Abstraction- , abstract, abstract1+ , abstract, abstract1, abstractEither -- * Instantiation- , instantiate, instantiate1+ , instantiate, instantiate1, instantiateEither -- * Traditional de Bruijn , fromScope , toScope@@ -90,6 +83,13 @@ import Data.Traversable import Prelude hiding (foldr, mapM, mapM_) import Data.Data+#if defined(__GLASGOW_HASKELL__)+#if __GLASGOW_HASKELL__ >= 706+import GHC.Generics ( Generic, Generic1 )+#else+import GHC.Generics ( Generic )+#endif+#endif -- $setup -- >>> import Bound.Var@@ -118,9 +118,15 @@ -- @f (Var b a)@, but the extra @f a@ inside permits us a cheaper 'lift'. -- newtype Scope b f a = Scope { unscope :: f (Var b (f a)) }-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707- deriving Typeable+#if defined(__GLASGOW_HASKELL__)+ deriving (Generic)+#if (__GLASGOW_HASKELL__ >= 707) && (__GLASGOW_HASKELL__ < 800)+deriving instance Typeable Scope #endif+#if __GLASGOW_HASKELL__ >= 706+deriving instance Functor f => Generic1 (Scope b f)+#endif+#endif ------------------------------------------------------------------------------- -- Instances@@ -148,7 +154,7 @@ -- | The monad permits substitution on free variables, while preserving -- bound variables instance Monad f => Monad (Scope b f) where-#if __GLASGOW_HASKELL__ < 710+#if !MIN_VERSION_base(4,8,0) return a = Scope (return (F (return a))) {-# INLINE return #-} #endif@@ -162,7 +168,7 @@ {-# INLINE lift #-} instance MFunctor (Scope b) where-#if __GLASGOW_HASKELL__ < 710+#if !MIN_VERSION_base(4,8,0) hoist t (Scope b) = Scope $ t (liftM (liftM t) b) #else hoist = hoistScope@@ -270,6 +276,15 @@ abstract1 a = abstract (\b -> if a == b then Just () else Nothing) {-# INLINE abstract1 #-} +-- | Capture some free variables in an expression to yield+-- a 'Scope' with bound variables in @b@. Optionally change the+-- types of the remaining free variables.+abstractEither :: Monad f => (a -> Either b c) -> f a -> Scope b f c+abstractEither f e = Scope (liftM k e) where+ k y = case f y of+ Left z -> B z+ Right y' -> F (return y')+ ------------------------------------------------------------------------------- -- Instantiation -------------------------------------------------------------------------------@@ -292,6 +307,13 @@ instantiate1 :: Monad f => f a -> Scope n f a -> f a instantiate1 e = instantiate (const e) {-# INLINE instantiate1 #-}++-- | Enter a scope, and instantiate all bound and free variables in one go.+instantiateEither :: Monad f => (Either b a -> f c) -> Scope b f a -> f c+instantiateEither f s = unscope s >>= \v -> case v of+ B b -> f (Left b)+ F ea -> ea >>= f . Right+{-# INLINE instantiateEither #-} ------------------------------------------------------------------------------- -- Traditional de Bruijn
src/Bound/Scope/Simple.hs view
@@ -4,18 +4,12 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE UndecidableInstances #-}--#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif -#endif--#ifndef MIN_VERSION_base-#define MIN_VERSION_base(x,y,z) 1-#endif ----------------------------------------------------------------------------- -- | -- Copyright : (C) 2013 Edward Kmett@@ -67,6 +61,7 @@ import Bound.Class import Bound.Var import Control.Applicative+import Control.DeepSeq import Control.Monad hiding (mapM, mapM_) import Control.Monad.Morph import Data.Bifunctor@@ -87,6 +82,13 @@ import Data.Serialize (Serialize) import Data.Traversable import Prelude hiding (foldr, mapM, mapM_)+#if defined(__GLASGOW_HASKELL__)+#if __GLASGOW_HASKELL__ >= 706+import GHC.Generics (Generic, Generic1)+#else+import GHC.Generics (Generic)+#endif+#endif -- $setup -- >>> import Bound.Var@@ -110,14 +112,24 @@ -- Another use case is for syntaxes not stable under substitution, -- therefore with only a 'Functor' instance and no 'Monad' instance. newtype Scope b f a = Scope { unscope :: f (Var b a) }+#if defined(__GLASGOW_HASKELL__)+ deriving Generic+#endif #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ > 707- deriving Typeable+deriving instance Typeable Scope #endif +#if __GLASGOW_HASKELL__ >= 706+deriving instance Functor f => Generic1 (Scope b f)+#endif+ ------------------------------------------------------------------------------- -- Instances ------------------------------------------------------------------------------- +instance NFData (f (Var b a)) => NFData (Scope b f a) where+ rnf (Scope x) = rnf x+ instance Functor f => Functor (Scope b f) where fmap f (Scope a) = Scope (fmap (fmap f) a) {-# INLINE fmap #-}@@ -131,7 +143,7 @@ traverse f (Scope a) = Scope <$> traverse (traverse f) a {-# INLINE traverse #-} -#if __GLASGOW_HASKELL__ < 710+#if !MIN_VERSION_base(4,8,0) instance (Functor f, Monad f) => Applicative (Scope b f) where #else instance Monad f => Applicative (Scope b f) where@@ -158,7 +170,7 @@ {-# INLINE lift #-} instance MFunctor (Scope b) where-#if __GLASGOW_HASKELL__ < 710+#if !MIN_VERSION_base(4,8,0) hoist f = hoistScope f #else hoist = hoistScope
src/Bound/TH.hs view
@@ -23,7 +23,7 @@ ) where #ifdef MIN_VERSION_template_haskell-import Data.List (intercalate, foldr1)+import Data.List (intercalate) import Data.Traversable (for) import Control.Monad (foldM, mzero, guard) import Bound.Class (Bound((>>>=)))@@ -379,7 +379,7 @@ (conName, [ t1, t2 ]) ForallC _ _ conName -> allTypeArgs conName-#if MIN_VERSION_template_haskell(0,2,11)+#if MIN_VERSION_template_haskell(2,11,0) _ -> error "Not implemented" #endif
src/Bound/Var.hs view
@@ -2,16 +2,9 @@ #ifdef __GLASGOW_HASKELL__ {-# LANGUAGE DeriveDataTypeable #-}--#if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE DeriveGeneric #-}-#endif--#if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-} #endif--#endif ----------------------------------------------------------------------------- -- | -- Copyright : (C) 2012 Edward Kmett@@ -29,16 +22,15 @@ , _F ) where -#if __GLASGOW_HASKELL__ < 710+#if !MIN_VERSION_base(4,8,0) import Control.Applicative-#endif-import Control.DeepSeq-import Control.Monad (liftM, ap)-#if __GLASGOW_HASKELL__ < 710 import Data.Foldable import Data.Traversable import Data.Monoid (Monoid(..))+import Data.Word #endif+import Control.DeepSeq+import Control.Monad (liftM, ap) import Data.Hashable (Hashable(..)) import Data.Hashable.Lifted (Hashable1(..), Hashable2(..)) import Data.Bifunctor@@ -50,17 +42,12 @@ import Data.Bytes.Put import Data.Bytes.Serial import Data.Functor.Classes-#ifdef __GLASGOW_HASKELL__-import Data.Data-# if __GLASGOW_HASKELL__ >= 704-import GHC.Generics-# endif-#endif import Data.Profunctor import qualified Data.Serialize as Serialize import Data.Serialize (Serialize)-#if __GLASGOW_HASKELL__ < 710-import Data.Word+#ifdef __GLASGOW_HASKELL__+import Data.Data+import GHC.Generics #endif ----------------------------------------------------------------------------@@ -84,10 +71,11 @@ #ifdef __GLASGOW_HASKELL__ , Data , Typeable-# if __GLASGOW_HASKELL__ >= 704 , Generic-# endif+# if __GLASGOW_HASKELL__ >= 706+ , Generic1 #endif+#endif ) distinguisher :: Int@@ -251,6 +239,6 @@ instance Read b => Read1 (Var b) where readsPrec1 = readsPrec #endif -# if __GLASGOW_HASKELL__ >= 704-instance (NFData a, NFData b) => NFData (Var b a)-# endif+instance (NFData a, NFData b) => NFData (Var b a) where+ rnf (B b) = rnf b+ rnf (F f) = rnf f