Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data State a = State (Int -> (a, Int))
- instance Monad State where
- return x = State $ s -> (x, s)
- (State f) >>= k = State $ s ->
- let
- (x, s') = f s
- State f' = k x
- in f' s'
- get :: State Int
- get = State $ s -> (s, s)
- put :: Int -> State ()
- put s = State $ _ -> ((), s)
- increment :: State ()
- increment = do
- a <- get
- put(a+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement