State is a Monad Transformer
Can we ”lift” actions in the underlying monad?
Yes -- they don’t change the state!
newtype State s m a = State (s -> m (s,a))
instance MonadTransformer (State s) m where
lift a = State $ \s ->
do x <- a
return (s,x)
Föregående bild
Nästa bild
Tillbaka till första bilden
Visa grafisk version