[Haskell-beginners] map question
Joost Kremers
joostkremers at fastmail.fm
Thu Sep 17 07:31:38 EDT 2009
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
More information about the Beginners
mailing list