Skip to content

Instantly share code, notes, and snippets.

@aboekhoff
Created April 22, 2010 16:36
Show Gist options
  • Save aboekhoff/375462 to your computer and use it in GitHub Desktop.
Save aboekhoff/375462 to your computer and use it in GitHub Desktop.
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