[Haskell-beginners] map question

Tom Doris tomdoris at gmail.com
Thu Sep 17 09:06:23 EDT 2009


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090917/3d8634f3/attachment.html


More information about the Beginners mailing list