Created
May 29, 2012 08:13
-
-
Save notyy/2823232 to your computer and use it in GitHub Desktop.
State monad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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