Skip to content

Commit 81dd7fd

Browse files
authored
Merge pull request #84 from mlang/alternativeRWST
Add missing Plus and Alternative instances for RWST
2 parents 7b82f15 + 2018f27 commit 81dd7fd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Control/Monad/RWS/Trans.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ module Control.Monad.RWS.Trans
99
import Prelude
1010

1111
import Control.Alt (class Alt, (<|>))
12+
import Control.Alternative (class Alternative)
1213
import Control.Monad.Eff.Class (class MonadEff, liftEff)
1314
import Control.Monad.Error.Class (class MonadError, throwError, catchError)
1415
import Control.Monad.Reader.Class (class MonadAsk, class MonadReader)
1516
import Control.Monad.Rec.Class (class MonadRec, tailRecM, Step(..))
1617
import Control.Monad.State.Class (class MonadState)
1718
import Control.Monad.Trans.Class (class MonadTrans, lift)
1819
import Control.Monad.Writer.Class (class MonadWriter, class MonadTell)
20+
import Control.Plus (class Plus, empty)
1921

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

67+
instance alternativeRWST :: (Monoid w, Alternative m, Monad m) => Alternative (RWST r w s m)
68+
6569
instance bindRWST :: (Bind m, Monoid w) => Bind (RWST r w s m) where
6670
bind (RWST m) f = RWST \r s ->
6771
m r s >>= \(RWSResult s' a w) ->
@@ -119,3 +123,6 @@ instance monadRecRWST :: (MonadRec m, Monoid w) => MonadRec (RWST r w s m) where
119123
pure case result' of
120124
Loop x -> Loop (RWSResult state' x (writer <> writer'))
121125
Done y -> Done (RWSResult state' y (writer <> writer'))
126+
127+
instance plusRWST :: Plus m => Plus (RWST r w s m) where
128+
empty = RWST \ _ _ -> empty

0 commit comments

Comments
 (0)