[Haskell-cafe] Precedence (Part 2)

PR Stanley prstanley at ntlworld.com
Thu Apr 3 13:42:09 EDT 2008


Hi folks

 > let f = sum.map (^2).filter even
 > f [1..4]
20

So far so good!

 > sum.map (^2).filter even [1..4]
returns an error.

How is it that the composition above as part of a function equation
doesn't return any errors while on its own it requires parentheses?

You seem to have expression evaluation confused with cpp/m4 macros.
The `f' in `f [1..4]' is not expanded as text to `sum.map (^2).filter
even [1..4]'; it is evaluated as a function whose definition will
(when needed!  lazy language) eventually turn out to be `sum.map
(^2).filter even'.

If you really must view it as a text macro substitution, then imagine
that every macro expansion has a set of parentheses added around it.

-- 
	Okay, so it's not expanded like a CPP macro. How is it evaluated? 
What happens to the sum.map ... definition if it's not simply used to 
substitute f?
	Thanks, Paul



More information about the Haskell-Cafe mailing list