Skip to content

Instantly share code, notes, and snippets.

@berdario berdario/foo.hs
Created Jul 22, 2016

Embed
What would you like to do?
State monad does not force ordering
import Control.Monad.State (execState, get, modify)
import Debug.Trace (trace)
foo :: IO ()
foo = do
(x, y) <- pure $ flip execState (1,1) $ do
(x, y) <- get
modify (\(x, y) -> (trace "x1" (x+1), (trace "y1" y)))
(x, y) <- get
modify (\(x, y) -> (trace "x2" x, trace "y2" (y*3)))
print y
print x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.