free 3.4.2 → 4.0
raw patch · 5 files changed
+34/−16 lines, 5 filesdep −comonad-transformersdep −comonads-fddep ~bifunctorsdep ~comonaddep ~profunctors
Dependencies removed: comonad-transformers, comonads-fd
Dependency ranges changed: bifunctors, comonad, profunctors, semigroupoids, semigroups
Files
- CHANGELOG.markdown +6/−0
- free.cabal +8/−10
- src/Control/Comonad/Cofree/Class.hs +8/−0
- src/Control/Monad/Free.hs +6/−2
- src/Control/Monad/Free/Class.hs +6/−4
CHANGELOG.markdown view
@@ -1,3 +1,9 @@+4.0+---+* Updated to work with `semigroupoids` and `comonad` 4.0+* `instance ComonadCofree Maybe NonEmpty`+* `instance ComonadCofree (Const b) ((,) b)`+ 3.4.2 ----- * Generalized `liftF`.
free.cabal view
@@ -1,6 +1,6 @@ name: free category: Control, Monads-version: 3.4.2+version: 4.0 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE@@ -52,17 +52,15 @@ GADTs build-depends:- base >= 4 && < 5,- bifunctors >= 3,+ base == 4.*,+ bifunctors == 3.*,+ comonad == 4.*, distributive >= 0.2.1,- transformers >= 0.2.0 && < 0.4, mtl >= 2.0.1.0 && < 2.2,- semigroupoids >= 3,- comonad >= 3,- comonad-transformers >= 3,- comonads-fd >= 3,- semigroups >= 0.8.3.1,- profunctors >= 3.2 && < 4+ profunctors == 4.*,+ semigroupoids == 4.*,+ semigroups >= 0.8.3.1 && < 1,+ transformers >= 0.2.0 && < 0.4 if impl(ghc) cpp-options: -DGHC_TYPEABLE
src/Control/Comonad/Cofree/Class.hs view
@@ -22,12 +22,20 @@ import Control.Comonad.Trans.Store import Control.Comonad.Trans.Traced import Control.Comonad.Trans.Identity+import Data.List.NonEmpty import Data.Semigroup -- | Allows you to peel a layer off a cofree comonad. class (Functor f, Comonad w) => ComonadCofree f w | w -> f where -- | Remove a layer. unwrap :: w a -> f (w a)++instance ComonadCofree Maybe NonEmpty where+ unwrap (_ :| []) = Nothing+ unwrap (_ :| (a : as)) = Just (a :| as)++instance ComonadCofree (Const b) ((,) b) where+ unwrap = Const . fst instance ComonadCofree f w => ComonadCofree f (IdentityT w) where unwrap = fmap IdentityT . unwrap . runIdentityT
src/Control/Monad/Free.hs view
@@ -32,6 +32,7 @@ import Control.Applicative import Control.Monad (liftM, MonadPlus(..))+import Control.Monad.Fix import Control.Monad.Trans.Class import Control.Monad.Free.Class import Control.Monad.Reader.Class@@ -86,8 +87,8 @@ -- -- This can be very useful for modeling domain specific languages, trees, or other constructs. ----- This instance of 'MonadFree' is fairly naive about the encoding. For more efficient free monad implementations that require additional--- extensions and thus aren't included here, you may want to look at the @kan-extensions@ package.+-- This instance of 'MonadFree' is fairly naive about the encoding. For more efficient free monad implementation see "Control.Monad.Free.Church", in particular note the 'Control.Monad.Free.Church.improve' combinator.+-- You may also want to take a look at the @kan-extensions@ package (<http://hackage.haskell.org/package/kan-extensions>). -- -- A number of common monads arise as free monads, --@@ -153,6 +154,9 @@ {-# INLINE return #-} Pure a >>= f = f a Free m >>= f = Free ((>>= f) <$> m)++instance Functor f => MonadFix (Free f) where+ mfix f = a where a = f (impure a); impure (Pure x) = x; impure (Free _) = error "mfix (Free f): Free" -- | This violates the Alternative laws, handle with care. instance Alternative v => Alternative (Free v) where
src/Control/Monad/Free/Class.hs view
@@ -37,7 +37,7 @@ -- | -- Monads provide substitution ('fmap') and renormalization ('Control.Monad.join'): ----- @m '>>=' f = 'Control.Monad.join' . 'fmap' f m@+-- @m '>>=' f = 'Control.Monad.join' ('fmap' f m)@ -- -- A free 'Monad' is one that does no work during the normalization step beyond simply grafting the two monadic values together. --@@ -72,9 +72,11 @@ -- Or we could choose to program with @'Control.Monad.Free.Free' Pair@ instead of 'Tree' -- and thereby avoid having to define our own 'Monad' instance. ----- Moreover, the @kan-extensions@ package provides 'MonadFree' instances that can--- improve the /asymptotic/ complexity of code that constructors free monads by--- effectively reassociating the use of ('>>=').+-- Moreover, "Control.Monad.Free.Church" provides a 'MonadFree'+-- instance that can improve the /asymptotic/ complexity of code that+-- constructs free monads by effectively reassociating the use of+-- ('>>='). You may also want to take a look at the @kan-extensions@+-- package (<http://hackage.haskell.org/package/kan-extensions>). -- -- See 'Control.Monad.Free.Free' for a more formal definition of the free 'Monad' -- for a 'Functor'.