Skip to content

add Semigroup and Monoid instances #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Control/Monad/Free.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Control.Monad.Free

import Prelude

import Control.Apply (lift2)
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM)
import Control.Monad.Trans.Class (class MonadTrans)

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

instance semigroupFree :: Semigroup a => Semigroup (Free f a) where
append = lift2 append

instance monoidFree :: Monoid a => Monoid (Free f a) where
mempty = pure mempty

-- | Lift an impure value described by the generating type constructor `f` into
-- | the free monad.
liftF :: forall f. f ~> Free f
Expand Down