Advertisement
Guest User

Untitled

a guest
Nov 29th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. data State a = State (Int -> (a, Int))
  2.  
  3. instance Monad State where
  4. return x = State $ s -> (x, s)
  5.  
  6. (State f) >>= k = State $ s ->
  7. let
  8. (x, s') = f s
  9. State f' = k x
  10. in f' s'
  11.  
  12. get :: State Int
  13. get = State $ s -> (s, s)
  14.  
  15. put :: Int -> State ()
  16. put s = State $ _ -> ((), s)
  17.  
  18. increment :: State ()
  19. increment = do
  20. a <- get
  21. put(a+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement