on master help sign in
Functor instance for StateT.
commit015200aca80ad3203438d3a3cf39db469c7e7cc4 authorstartling <tdixon51793@gmail.com> dateMon 19 Nov 2012, 12:12 (14 years ago) parentd13c4ba
1 file changed+6
lib/Control/Monad/State.idr+6
lib/Control/Monad/State.idr+6
@@ -2,6 +2,7 @@ module Control.Monad.State
22
33import Control.Monad.Identity
44import Prelude.Monad
5+import Prelude.Functor
56
67%access public
78
@@ -13,6 +14,11 @@ record StateT : Set -> (Set -> Set) -> Set -> Set where
1314 ST : {m : Set -> Set} ->
1415 (runStateT : s -> m (a, s)) -> StateT s m a
1516
17+instance Functor f => Functor (StateT s f) where
18+ fmap f (ST g) = ST (\st => fmap (mapFst f) (g st)) where
19+ mapFst : (a -> x) -> (a, b) -> (x, b)
20+ mapFst fn (a, b) = (fn a, b)
21+
1622instance Monad m => Monad (StateT s m) where
1723 return x = ST (\st => return (x, st))
1824