(-) happens to be the only prefix operator in haskell, it also an infix operator. so: > 4 - 2 2 > -3 -3
> ((-) 5) 3 -- note that in this case (-) is treated like any regular function so 5 is the first parameter 2 > (5 - ) 3 2 > (-5 ) -5 > (flip (-) 5) 3 -2 It's a little wart brought about by the ambiguity in common mathematical syntax. If you play around in ghci you should get the hang of it pretty quick. - Job On Thu, Sep 17, 2009 at 11:08 AM, Gregory Propf <gregorypr...@yahoo.com>wrote: > Remember that there is asymmetry between (+) and (-). The former has the > commutative property and the latter does not so: > > (+) 3 4 = 7 > > and > > (+) 4 3 = 7 > > but > > (-) 3 4 = -1 > > and > > (-) 4 3 = 1 > > --- On *Thu, 9/17/09, Tom Doris <tomdo...@gmail.com>* wrote: > > > From: Tom Doris <tomdo...@gmail.com> > Subject: Re: [Haskell-beginners] map question > To: "Joost Kremers" <joostkrem...@fastmail.fm> > Cc: beginn...@haskell.org > Date: Thursday, September 17, 2009, 6:06 AM > > This works: > > map (+ (-1)) [1,2,3,4] > > > 2009/9/17 Joost Kremers > <joostkrem...@fastmail.fm<http://mc/compose?to=joostkrem...@fastmail.fm> > > > >> Hi all, >> >> I've just started learning Haskell and while experimenting with map a bit, >> I ran >> into something I don't understand. The following commands do what I'd >> expect: >> >> Prelude> map (+ 1) [1,2,3,4] >> [2,3,4,5] >> Prelude> map (* 2) [1,2,3,4] >> [2,4,6,8] >> Prelude> map (/ 2) [1,2,3,4] >> [0.5,1.0,1.5,2.0] >> Prelude> map (2 /) [1,2,3,4] >> [2.0,1.0,0.6666666666666666,0.5] >> >> But I can't seem to find a way to get map to substract 1 from all members >> of the >> list. The following form is the only one that works, but it doesn't give >> the >> result I'd expect: >> >> Prelude> map ((-) 1) [1,2,3,4] >> [0,-1,-2,-3] >> >> I know I can use an anonymous function, but I'm just trying to understand >> the >> result here... I'd appreciate any hints to help me graps this. >> >> TIA >> >> Joost >> >> >> -- >> Joost Kremers, PhD >> University of Frankfurt >> Institute for Cognitive Linguistics >> Grüneburgplatz 1 >> 60629 Frankfurt am Main, Germany >> _______________________________________________ >> Beginners mailing list >> beginn...@haskell.org <http://mc/compose?to=beginn...@haskell.org> >> http://www.haskell.org/mailman/listinfo/beginners >> > > > -----Inline Attachment Follows----- > > _______________________________________________ > Beginners mailing list > beginn...@haskell.org <http://mc/compose?to=beginn...@haskell.org> > http://www.haskell.org/mailman/listinfo/beginners > > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe