Skip to content

Commit f686f5f

Browse files
safareligaryb
authored andcommitted
add Semigroup and Monoid instances (#98)
* add Semigroup and Monoid instances * oops * white
1 parent f6c139e commit f686f5f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Control/Monad/Free.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Control.Monad.Free
1414

1515
import Prelude
1616

17+
import Control.Apply (lift2)
1718
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM)
1819
import Control.Monad.Trans.Class (class MonadTrans)
1920

@@ -111,6 +112,12 @@ instance traversableFree :: Traversable f => Traversable (Free f) where
111112
Right a -> pure <$> f a
112113
sequence tma = traverse identity tma
113114

115+
instance semigroupFree :: Semigroup a => Semigroup (Free f a) where
116+
append = lift2 append
117+
118+
instance monoidFree :: Monoid a => Monoid (Free f a) where
119+
mempty = pure mempty
120+
114121
-- | Lift an impure value described by the generating type constructor `f` into
115122
-- | the free monad.
116123
liftF :: forall f. f ~> Free f

0 commit comments

Comments
 (0)