Skip to content

Commit

Permalink
Merge pull request #61 from xuwei-k/WriterT-Semigroup
Browse files Browse the repository at this point in the history
relax WriterT instance constraints
  • Loading branch information
paf31 committed Nov 1, 2015
2 parents a46b635 + 07b768b commit 25935d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions docs/Control/Monad/Writer/Trans.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ The `MonadWriter` type class describes the operations supported by this monad.
##### Instances
``` purescript
instance functorWriterT :: (Functor m) => Functor (WriterT w m)
instance applyWriterT :: (Monoid w, Apply m) => Apply (WriterT w m)
instance applyWriterT :: (Semigroup w, Apply m) => Apply (WriterT w m)
instance applicativeWriterT :: (Monoid w, Applicative m) => Applicative (WriterT w m)
instance altWriterT :: (Monoid w, Alt m) => Alt (WriterT w m)
instance plusWriterT :: (Monoid w, Plus m) => Plus (WriterT w m)
instance altWriterT :: (Alt m) => Alt (WriterT w m)
instance plusWriterT :: (Plus m) => Plus (WriterT w m)
instance alternativeWriterT :: (Monoid w, Alternative m) => Alternative (WriterT w m)
instance bindWriterT :: (Monoid w, Monad m) => Bind (WriterT w m)
instance bindWriterT :: (Semigroup w, Monad m) => Bind (WriterT w m)
instance monadWriterT :: (Monoid w, Monad m) => Monad (WriterT w m)
instance monadRecWriterT :: (Monoid w, MonadRec m) => MonadRec (WriterT w m)
instance monadPlusWriterT :: (Monoid w, MonadPlus m) => MonadPlus (WriterT w m)
Expand Down
8 changes: 4 additions & 4 deletions src/Control/Monad/Writer/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ mapWriterT f m = WriterT $ f (runWriterT m)
instance functorWriterT :: (Functor m) => Functor (WriterT w m) where
map f = mapWriterT $ (<$>) \(Tuple a w) -> Tuple (f a) w

instance applyWriterT :: (Monoid w, Apply m) => Apply (WriterT w m) where
instance applyWriterT :: (Semigroup w, Apply m) => Apply (WriterT w m) where
apply f v = WriterT $
let k (Tuple a w) (Tuple b w') = Tuple (a b) (w <> w')
in k <$> (runWriterT f) <*> (runWriterT v)

instance applicativeWriterT :: (Monoid w, Applicative m) => Applicative (WriterT w m) where
pure a = WriterT $ pure $ Tuple a mempty

instance altWriterT :: (Monoid w, Alt m) => Alt (WriterT w m) where
instance altWriterT :: (Alt m) => Alt (WriterT w m) where
alt m n = WriterT $ runWriterT m <|> runWriterT n

instance plusWriterT :: (Monoid w, Plus m) => Plus (WriterT w m) where
instance plusWriterT :: (Plus m) => Plus (WriterT w m) where
empty = WriterT empty

instance alternativeWriterT :: (Monoid w, Alternative m) => Alternative (WriterT w m)

instance bindWriterT :: (Monoid w, Monad m) => Bind (WriterT w m) where
instance bindWriterT :: (Semigroup w, Monad m) => Bind (WriterT w m) where
bind m k = WriterT $ do
Tuple a w <- runWriterT m
Tuple b w' <- runWriterT (k a)
Expand Down

0 comments on commit 25935d1

Please sign in to comment.