Skip to content

Commit 293ae76

Browse files
authored
Merge pull request #12 from eric-corumdigital/master
ADD: Semigroup instance for Mu
2 parents cb1800e + cd1c9ed commit 293ae76

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Data/Functor/Mu.purs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ module Data.Functor.Mu
66
) where
77

88
import Prelude
9-
import Data.TacitString as TS
109

10+
import Control.Alt (class Alt, (<|>))
11+
import Control.Alternative (class Plus, empty)
1112
import Data.Eq (class Eq1, eq1)
1213
import Data.Newtype (class Newtype)
1314
import Data.Ord (class Ord1, compare1)
15+
import Data.TacitString as TS
1416

1517
-- | `Mu f` is the least fixed point of a functor `f`, when it exists.
1618
newtype Mu f = In (f (Mu f))
@@ -49,3 +51,9 @@ instance ordMu :: (Eq1 f, Ord1 f) => Ord (Mu f) where
4951
-- extra quotes from appearing.
5052
instance showMu :: (Show (f TS.TacitString), Functor f) => Show (Mu f) where
5153
show (In x) = show $ x <#> (show >>> TS.hush)
54+
55+
instance semigroupMu :: Alt f => Semigroup (Mu f) where
56+
append (In x) (In y) = In (x <|> y)
57+
58+
instance monoidMu :: Plus f => Monoid (Mu f) where
59+
mempty = In empty

0 commit comments

Comments
 (0)