Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@berdario
Created July 22, 2016 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berdario/12515c23556b3fba751c2582d330b382 to your computer and use it in GitHub Desktop.
Save berdario/12515c23556b3fba751c2582d330b382 to your computer and use it in GitHub Desktop.
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