Created
April 22, 2010 16:36
-
-
Save aboekhoff/375462 to your computer and use it in GitHub Desktop.
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
module Kumochan where | |
import Monad | |
import Control.Monad.State | |
data Env = Env {nodeId::Int, symId::Int} deriving (Show) | |
root = Env (-1) (-1) | |
nextNodeId :: Env -> (Int, Env) | |
nextNodeId = runState (do (Env a b) <- get | |
a' <- return $ a + 1 | |
put $ Env a' b | |
return a') | |
-- no problem, replacing nextNodeId with: | |
nextSymId :: Env -> (Int, Env) | |
nextSymId = runState (do (Env a b) <- get | |
b' <- return $ b + 1 | |
put $ Env a b' | |
return b') | |
-- is also no problem, yet pasting the second after the first | |
-- results in: the last statement in a do construct must be an expression | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment