Skip to content

Instantly share code, notes, and snippets.

@23Skidoo
Created May 8, 2011 11:06
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 23Skidoo/961307 to your computer and use it in GitHub Desktop.
Save 23Skidoo/961307 to your computer and use it in GitHub Desktop.
Modified sequencing monad
-- See
-- http://stackoverflow.com/questions/5920200/how-to-prevent-common-sub-expression-elimination-cse-with-ghc
module Main
where
import Debug.Trace
data Eval a = Done a
| Trace String a
instance Monad Eval where
return x = Done x
Done x >>= k = k x
Trace s a >>= k = k (trace s a)
runEval :: Eval a -> a
runEval (Done x) = x
runEval (Trace s a) = trace s a
track :: String -> a -> Eval a
track = Trace
main :: IO ()
main = print $ runEval $ do
t1 <- track "hit 1" 1
t2 <- track "hit 2" 2
return (t2 + t1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment