Skip to content

Commit

Permalink
tests for State and StateT:
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymorris committed Nov 11, 2015
1 parent b7f323f commit e1ac210
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Course/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ instance Applicative (State s) where
error "todo: Course.State (<*>)#instance (State s)"

-- | Implement the `Bind` instance for `State s`.
--
-- >>> runState ((const $ put 2) =<< put 1) 0
-- ((),2)
--
-- >>> let modify f = State (\s -> ((), f s)) in runState (modify (+1) >>= \() -> modify (*2)) 7
-- ((),16)
instance Monad (State s) where
(=<<) ::
(a -> State s b)
Expand Down
3 changes: 3 additions & 0 deletions src/Course/StateT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ instance Monad f => Applicative (StateT s f) where
--
-- >>> runStateT ((const $ putT 2) =<< putT 1) 0
-- ((),2)
--
-- >>> let modify f = StateT (\s -> pure ((), f s)) in runStateT (modify (+1) >>= \() -> modify (*2)) 7
-- ((),16)
instance Monad f => Monad (StateT s f) where
(=<<) ::
(a -> StateT s f b)
Expand Down

0 comments on commit e1ac210

Please sign in to comment.