polytree 0.0.2 → 0.0.3
raw patch · 3 files changed
+38/−1 lines, 3 files
Files
- changelog.md +4/−0
- polytree.cabal +1/−1
- src/Data/PolyTree.hs +33/−0
changelog.md view
@@ -1,3 +1,7 @@+0.0.3++* Add Semigroup and Monoid instance+ 0.0.2 * Add more optics and functions
polytree.cabal view
@@ -1,5 +1,5 @@ name: polytree-version: 0.0.2+version: 0.0.3 synopsis: A polymorphic rose-tree description: A rose-tree which has different data in the nodes and leaves license: BSD3
src/Data/PolyTree.hs view
@@ -4,6 +4,7 @@ module Data.PolyTree where +import Control.Applicative import Control.Lens ( preview, iso,@@ -112,6 +113,38 @@ instance (Show a, Show1 f, Show b) => Show (Tree f a b) where show x = liftShowsPrec showsPrec shows 0 x ""++-- |+--+-- >>> Leaf "ABC" <> Leaf "DEF" :: Tree1' String+-- Leaf "ABCDEF"+--+-- >>> Leaf "ABC" <> Node "DEF" [] :: Tree0' String+-- Node "DEF" []+--+-- >>> Leaf "ABC" <> Node "DEF" [Leaf "GHI"] :: Tree0' String+-- Node "DEF" [Leaf "ABCGHI"]+--+-- >>> Node "ABC" [] <> Leaf "DEF" :: Tree0' String+-- Node "ABC" []+--+-- >>> Node "ABC" [] <> Node "DEF" [Leaf "GHI"] :: Tree0' String+-- Node "ABCDEF" []+--+-- >>> Node "ABC" [] <> Node "DEF" [Leaf "GHI", Node "JKL" []] :: Tree0' String+-- Node "ABCDEF" []+instance (Applicative f, Semigroup a, Semigroup b) => Semigroup (Tree f a b) where+ Leaf a1 <> Leaf a2 =+ Leaf (a1 <> a2)+ Leaf a <> Node b t =+ Node b (fmap (Leaf a <>) t)+ Node b t <> Leaf a =+ Node b (fmap (Leaf a <>) t)+ Node b1 t1 <> Node b2 t2 =+ Node (b1 <> b2) (liftA2 (<>) t1 t2)++instance (Applicative f, Monoid a, Monoid b) => Monoid (Tree f a b) where+ mempty = Leaf mempty -- | --