Skip to content

Instantly share code, notes, and snippets.

@berdario
Created July 22, 2016 14:19
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/2416b3bcd07a503822fff0579f4f7ca5 to your computer and use it in GitHub Desktop.
Save berdario/2416b3bcd07a503822fff0579f4f7ca5 to your computer and use it in GitHub Desktop.
Constant Applicative Form sharing/evaluation (will get different output in ghci or when compiled)
foo :: String -> IO ()
foo dummy = do
let (x, y) = (1, 1)
(x, y) <- pure $ (trace "x" (x+1), (trace "y" y*3)
print $ show (y + y) <> dummy
print $ show (x + x) <> dummy
foo2 x = foo (trace "outerfoo" "foo")
foo3 xs dummy = print $ show (map (+1) xs) <> dummy
foo4 = foo3 [trace "1" 1,2,3]
foo5 dummy = print $ show (map (+1) [trace "1" 1,2,3]) <> dummy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment