
On Tue, Mar 06, 2007 at 10:19:12PM +0000, David House wrote:
On 06/03/07, Nicolas Frisby
wrote: Composition with (.) builds a function, but you eventually want an Int, so we can't just use (.), but we can come pretty close.
(sum . IntMap.elems . IntMap.IntersectionWith (\x y -> x*y) queryVector) rationalProjection
Often written:
f . g . h $ x
Alternativly, (f . g . h) x will work, too.
This is often prefered to the alternative:
f $ g $ h $ x
As it's visually lighter, and involves less editing if you wanted to get rid of the x (say, you were eta-reducing the expression).
As to why:
f . g . h . x
doesn't work, (.) can only compose two functions, but x is not a function, it is a value, so you have to apply it to the composite function f . g . h using the ($) operator or parentheses.
-- -David House, dmhouse@gmail.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe