Heh, perhaps we should petition to have a new computer key and symbol added to the world's way of writing maths, something like maybe a downward angled slash to mean prefix (-)
:) --- On Thu, 9/17/09, Job Vranish <[email protected]> wrote: From: Job Vranish <[email protected]> Subject: Re: [Haskell-cafe] Re: [Haskell-beginners] map question To: "Gregory Propf" <[email protected]> Cc: "Tom Doris" <[email protected]>, "Haskell-Cafe" <[email protected]>, [email protected] Date: Thursday, September 17, 2009, 9:04 AM (-) 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 <[email protected]> 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 <[email protected]> wrote: From: Tom Doris <[email protected]> Subject: Re: [Haskell-beginners] map question To: "Joost Kremers" <[email protected]> Cc: [email protected] Date: Thursday, September 17, 2009, 6:06 AM This works: map (+ (-1)) [1,2,3,4] 2009/9/17 Joost Kremers <[email protected]> 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 [email protected] http://www.haskell.org/mailman/listinfo/beginners -----Inline Attachment Follows----- _______________________________________________ Beginners mailing list [email protected] http://www.haskell.org/mailman/listinfo/beginners _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
