Skip to content

Add missing Plus and Alternative instances for RWST #84

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 1 commit into from
Jan 20, 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
7 changes: 7 additions & 0 deletions src/Control/Monad/RWS/Trans.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ module Control.Monad.RWS.Trans
import Prelude

import Control.Alt (class Alt, (<|>))
import Control.Alternative (class Alternative)
import Control.Monad.Eff.Class (class MonadEff, liftEff)
import Control.Monad.Error.Class (class MonadError, throwError, catchError)
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader)
import Control.Monad.Rec.Class (class MonadRec, tailRecM, Step(..))
import Control.Monad.State.Class (class MonadState)
import Control.Monad.Trans.Class (class MonadTrans, lift)
import Control.Monad.Writer.Class (class MonadWriter, class MonadTell)
import Control.Plus (class Plus, empty)

import Data.Monoid (class Monoid, mempty)
import Data.Newtype (class Newtype)
Expand Down Expand Up @@ -62,6 +64,8 @@ instance applyRWST :: (Bind m, Monoid w) => Apply (RWST r w s m) where
instance altRWST :: Alt m => Alt (RWST r w s m) where
alt (RWST m) (RWST n) = RWST $ \ r s -> m r s <|> n r s

instance alternativeRWST :: (Monoid w, Alternative m, Monad m) => Alternative (RWST r w s m)

instance bindRWST :: (Bind m, Monoid w) => Bind (RWST r w s m) where
bind (RWST m) f = RWST \r s ->
m r s >>= \(RWSResult s' a w) ->
Expand Down Expand Up @@ -119,3 +123,6 @@ instance monadRecRWST :: (MonadRec m, Monoid w) => MonadRec (RWST r w s m) where
pure case result' of
Loop x -> Loop (RWSResult state' x (writer <> writer'))
Done y -> Done (RWSResult state' y (writer <> writer'))

instance plusRWST :: Plus m => Plus (RWST r w s m) where
empty = RWST \ _ _ -> empty