notes/pl/hs/ct/monads/monad-state.txt
Ihar Hancharenka 5dff80e88e first
2023-03-27 16:52:17 +03:00

25 строки
635 B
Plaintext

https://www.fpcomplete.com/school/starting-with-haskell/basics-of-haskell/12-State-Monad
State Monad:
newtype State s a = State { runState :: (s -> (a,s)) }
instance Monad (State s) where
return a = State $ \s -> (a,s)
(State x) >>= f = State $ \s -> let (v,s1) = x s in runState (f v) s1
class MonadState m s | m -> s where
get :: m s
put :: s -> m ()
instance MonadState (State s) s where
get = State $ \s -> (s,s)
put s = State $ \_ -> ((),s)
instance MonadPlus (State s) where
mzero = ...
mplus = ...
http://stackoverflow.com/questions/5541828/haskell-state-monad-and-monadic-guard