[Haskell-cafe] Usage of . and $
Jeff Polakow
jeff.polakow at db.com
Tue Mar 6 15:14:39 EST 2007
haskell-cafe-bounces at haskell.org wrote on 03/06/2007 02:43:03 PM:
> Usually, I can do this, but today, my brain is weak, and I'm just trying
to
> get this piece of code out the door. My code looks like this:
>
> weight = sum (IntMap.elems (IntMap.intersectionWith
> (\x y -> x*y) queryVector rationalProjection))
>
> I know that this will work (ignoring indentation):
>
> sum $ IntMap.elems $ IntMap.intersectionWith (\x y -> x*y) queryVector
> rationalProjection
>
> But why won't this?:
>
> sum . IntMap.elems . IntMap.IntersectionWith ...
>
> Is there a difference between the "elegance" of function composition
versus
> application?
>
I assume your really asking why something like:
(*) $ 2 $ 3
won't work? If so, the reason is that $ associates to the right. So you
should write:
((*) $ 2) $ 3
If not, could you give the full expression which doesn't work?
-Jeff
---
This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070306/91cbcafe/attachment.htm
More information about the Haskell-Cafe
mailing list