forest 0.2 → 0.2.1
raw patch · 2 files changed
+29/−5 lines, 2 filesdep +comonaddep +freedep ~aesondep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: comonad, free
Dependency ranges changed: aeson, base
API changes (from Hackage documentation)
- Data.Tree.Forest: instance GHC.Base.Alternative f => GHC.Base.Monoid (Data.Tree.Forest.Forest f s a)
+ Data.Tree.Forest: free :: (Profunctor p, Functor f, Functor g) => p (Free (EnvT s g) a) (f (Free (EnvT s g) a)) -> p (Tree g s a) (f (Tree g s a))
+ Data.Tree.Forest: instance (Data.Functor.Alt.Alt f, GHC.Base.Alternative f) => GHC.Base.Monoid (Data.Tree.Forest.Forest f s a)
Files
- forest.cabal +5/−4
- src/Data/Tree/Forest.hs +24/−1
forest.cabal view
@@ -1,5 +1,5 @@ name: forest-version: 0.2+version: 0.2.1 synopsis: Tree and Forest types license: MPL-2.0 license-file: LICENSE@@ -24,13 +24,14 @@ Data.Tree.Forest build-depends:- aeson >= 0.2 && < 1.3,+ aeson >= 0.2 && < 1.4, base >= 4.2 && < 5,+ comonad >= 5.0 && < 6, deepseq >= 1.1 && < 2,+ free >= 4.12 && < 6, hashable >= 1.2 && < 2, profunctors >= 3.2 && < 6,- semigroupoids >= 1.0 && < 6,- base >= 4 && < 5+ semigroupoids >= 1.0 && < 6 if impl(ghc < 8) build-depends:
src/Data/Tree/Forest.hs view
@@ -30,6 +30,7 @@ , _Leaf , _Node , _Forest+ , free -- * Higher order traversals -- ** Trees@@ -133,10 +134,18 @@ import Prelude hiding (foldr1) +-- comonad -------------------------------------------------------------------+import Control.Comonad.Trans.Env (EnvT (EnvT))++ -- deepseq ------------------------------------------------------------------- import Control.DeepSeq (NFData, rnf) +-- free ----------------------------------------------------------------------+import Control.Monad.Free (Free (Free, Pure))++ -- hashable ------------------------------------------------------------------ import Data.Hashable (Hashable, hashWithSalt) @@ -202,6 +211,20 @@ ------------------------------------------------------------------------------+-- | This is an @Functor g => Iso' (Tree g s a) (Free (EnvT s g) a)@+free :: (Profunctor p, Functor f, Functor g)+ => p (Free (EnvT s g) a) (f (Free (EnvT s g) a))+ -> p (Tree g s a) (f (Tree g s a))+free = dimap to (fmap from)+ where+ from (Pure a) = Leaf a+ from (Free (EnvT s ts)) = Node s (Forest (fmap from ts))+ to (Leaf a) = Pure a+ to (Node s (Forest ts)) = Free (EnvT s (fmap to ts))+{-# INLINE free #-}+++------------------------------------------------------------------------------ instance (NFData s, NFData a, NFData (f (Tree f s a))) => NFData (Tree f s a) where@@ -627,7 +650,7 @@ -------------------------------------------------------------------------------instance Alternative f => Monoid (Forest f s a) where+instance (Alt f, Alternative f)=> Monoid (Forest f s a) where mempty = empty {-# INLINE mempty #-} mappend = (<|>)