Skip to content

Monoid instance for FreeT #8

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 6 commits into from
Jan 31, 2017
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
8 changes: 8 additions & 0 deletions src/Control/Monad/Free/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import Prelude
import Data.Bifunctor (bimap)
import Data.Either (Either(..))
import Data.Exists (Exists, mkExists, runExists)
import Data.Monoid (class Monoid, mempty)

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

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

instance semigroupFreeT :: (Functor f, Monad m, Semigroup w) => Semigroup (FreeT f m w) where
append = lift2 append

instance monoidFreeT :: (Functor f, Monad m, Monoid w) => Monoid (FreeT f m w) where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

mempty = pure mempty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise you only need Applicative m here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm not sure about that - FreeT's Apply instance depends on Monad due to the use of ap - I'm not sure if there's a way around that, I'm not too familiar with FreeT's design :x


-- | Lift an action from the functor `f` to a `FreeT` action.
liftFreeT :: forall f m a. (Functor f, Monad m) => f a -> FreeT f m a
liftFreeT fa = FreeT \_ -> pure (Right (map pure fa))
Expand Down