Personal tools

State Monad

From HaskellWiki

Revision as of 19:57, 24 May 2008 by Newsham (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The State Monad by Example

This is a short tutorial on the state monad. Emphasis is placed on intuition. The types have been simplified to protect the innocent.

Primitives

runState (return 'X') 1
('X',1)

Comments:

   initial state = 1 :: Int
   final value = 'X' :: Char
   final state = 1 :: Int
   result = ('X', 1) :: (Char, Int)