Skip to content

Relax instance requirements for bind/monad #48

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 2 commits into from
May 22, 2016
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
11 changes: 5 additions & 6 deletions src/Control/Comonad/Cofree.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module Control.Comonad.Cofree
import Prelude

import Control.Comonad (class Comonad)
import Control.Alt ((<|>))
import Control.MonadPlus (class MonadPlus)
import Control.Alternative (class Alternative, (<|>), empty)
import Control.Extend (class Extend)
import Control.Monad.Trampoline (Trampoline, runTrampoline)

Expand Down Expand Up @@ -82,12 +81,12 @@ instance applyCofree :: (Apply f) => Apply (Cofree f) where
h = (head f) (head x)
t = (<*>) <$> (tail f) <*> (tail x)

instance applicativeCofree :: (Applicative f) => Applicative (Cofree f) where
pure a = mkCofree a (pure $ pure a)
instance applicativeCofree :: (Alternative f) => Applicative (Cofree f) where
pure a = mkCofree a empty

instance bindCofree :: (MonadPlus f) => Bind (Cofree f) where
instance bindCofree :: (Alternative f) => Bind (Cofree f) where
bind fa f = loop fa where
loop fa = let fh = f (head fa)
in mkCofree (head fh) ((tail fh) <|> (loop <$> tail fa))

instance monadCofree :: (MonadPlus f) => Monad (Cofree f)
instance monadCofree :: (Alternative f) => Monad (Cofree f)