Skip to content

Commit 8152707

Browse files
athanclarkgaryb
authored andcommitted
Monoid instance for FreeT (#8)
1 parent 666f376 commit 8152707

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Control/Monad/Free/Trans.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import Prelude
1616
import Data.Bifunctor (bimap)
1717
import Data.Either (Either(..))
1818
import Data.Exists (Exists, mkExists, runExists)
19+
import Data.Monoid (class Monoid, mempty)
1920

21+
import Control.Apply (lift2)
2022
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM)
2123
import Control.Monad.Trans.Class (class MonadTrans)
2224

@@ -76,6 +78,12 @@ instance monadRecFreeT :: (Functor f, Monad m) => MonadRec (FreeT f m) where
7678
Loop s1 -> go s1
7779
Done a -> pure a
7880

81+
instance semigroupFreeT :: (Functor f, Monad m, Semigroup w) => Semigroup (FreeT f m w) where
82+
append = lift2 append
83+
84+
instance monoidFreeT :: (Functor f, Monad m, Monoid w) => Monoid (FreeT f m w) where
85+
mempty = pure mempty
86+
7987
-- | Lift an action from the functor `f` to a `FreeT` action.
8088
liftFreeT :: forall f m a. (Functor f, Monad m) => f a -> FreeT f m a
8189
liftFreeT fa = FreeT \_ -> pure (Right (map pure fa))

0 commit comments

Comments
 (0)