Skip to content

Instantly share code, notes, and snippets.

@ttuegel
Created January 24, 2015 00:09
Show Gist options
  • Save ttuegel/9a3be681985fc5837a38 to your computer and use it in GitHub Desktop.
Save ttuegel/9a3be681985fc5837a38 to your computer and use it in GitHub Desktop.
Function application versus evaluation
ghci> import Control.Monad (liftM)
ghci> :t liftM
liftM :: Monad m => (a1 -> r) -> m a1 -> m r
ghci> import Debug.Trace (trace)
ghci> liftM (\x -> trace "function applied" (x + 3)) [1 :: Int, 2, 3]
[function applied
4,function applied
5,function applied
6]
ghci> liftM (trace "function evaluated" (+ 3)) [1 :: Int, 2, 3]
[function evaluated
4,5,6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment