Skip to content

Instantly share code, notes, and snippets.

@notyy
Created May 29, 2012 08:13
Show Gist options
  • Save notyy/2823232 to your computer and use it in GitHub Desktop.
Save notyy/2823232 to your computer and use it in GitHub Desktop.
State monad
{-# LANGUAGE NoMonomorphismRestriction #-}
import Control.Monad.State
import Control.Monad.Identity
test1 = do -- when apply on init state 0
a <- get -- a = (0,0)
modify (+1) -- (0,1)
b <- get -- b = (1,1)
return (a,b) -- why result is ((0,1),1)
-----------------------
runState test1 0
((0,1),1) 为什么啊?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment