
17 Sep
2009
17 Sep
'09
8:01 a.m.
On Thu, Sep 17, 2009 at 01:31:38PM +0200, Joost Kremers wrote:
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]
By the way, the reason map (+1) [1,2,3,4] works but map (-1) [1,2,3,4] doesn't is because of an ugly corner of Haskell syntax: -1 here is parsed as negative one, rather than an operator section with subtraction. The 'subtract' function is provided exactly for this purpose, so that you can write map (subtract 1) [1,2,3,4] instead. -Brent