Add Alternative implementation for StateT
commitd281e667168461b19508fd0d8e8b89402f94554e
authorJoomy Korkut <joomy@cattheory.com>
dateTue 10 Oct 2017, 22:24 (9 years ago)
parent4e00dc2
libs/base/Control/Monad/State.idr+4
@@ -42,6 +42,10 @@ implementation MonadTrans (StateT stateType) where
4242 lift x = ST (\st => do r <- x
4343 pure (r, st))
4444
45+implementation (Monad f, Alternative f) => Alternative (StateT st f) where
46+ empty = lift empty
47+ (ST f) <|> (ST g) = ST (\st => f st <|> g st)
48+
4549||| Apply a function to modify the context of this computation
4650modify : MonadState stateType m => (stateType -> stateType) -> m ()
4751modify f = do s <- get