Though, as jozefg said, they are themselves equivalent, they may lead to different execution behaviour when combined with local variable bindings. Consider
f, f' :: Int -> Int -> Int
with the two definitions
f a x = μ*x
where μ = sum [1..a]
and
f' a = \x -> μ*x
where μ = sum [1..a]
These sure look equivalent, and certainly will always yield the same results.
GHCi, version 7.6.2: http://www.haskell.org/ghc/ :? for help
...
[1 of 1] Compiling Main ( def0.hs, interpreted )
Ok, modules loaded: Main.
*Main> sum $ map (f 10000) [1..10000]
2500500025000000
*Main> sum $ map (f' 10000) [1..10000]
2500500025000000
However, if you try this yourself, you'll notice that with f
takes quite a lot of time whereas with f'
you get the result immediately. The reason is that f'
is written in a form that prompts GHC to compile it so that actually f' 10000
is evaluated before starting to map it over the list. In that step, the value μ
is calculated and stored in the closure of (f' 10000)
. On the other hand, f
is treated simply as "one function of two variables"; (f 10000)
is merely stored as a closure containing the parameter 10000
and μ
is not calculated at all at first. Only when map
applies (f 10000)
to each element in the list, the whole sum [1..a]
is calculated, which takes some time for each element in [1..10000]
. With f'
, this was not necessary because μ
was pre-calculated.
In principle, common-subexpression elimination is an optimisation that GHC is able to do itself, so you might at times get good performance even with a definition like f
. But you can't really count on it.