[Haskell-cafe] Re: [Haskell-beginners] map question

Gregory Propf gregorypropf at yahoo.com
Thu Sep 17 11:08:09 EDT 2009


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 <tomdoris at gmail.com> wrote:

From: Tom Doris <tomdoris at gmail.com>
Subject: Re: [Haskell-beginners] map question
To: "Joost Kremers" <joostkremers at fastmail.fm>
Cc: beginners at haskell.org
Date: Thursday, September 17, 2009, 6:06 AM

This works:

map (+ (-1)) [1,2,3,4]


2009/9/17 Joost Kremers <joostkremers at 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

Beginners at haskell.org

http://www.haskell.org/mailman/listinfo/beginners




-----Inline Attachment Follows-----

_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090917/c21563a7/attachment.html


More information about the Haskell-Cafe mailing list