[Haskell-beginners] map increases length of list
Alan Mock
docmach at gmail.com
Wed Jun 17 17:55:36 EDT 2009
That's because [0,60,..359] is not the same as [0,60..359] ::
[Double]. So what you're passing to degreesToRadians is
[0.0,60.0,120.0,180.0,240.0,300.0,360.0] and not
[0,60,120,180,240,300]. I don't know why the Double version adds
another number, though.
On Jun 17, 2009, at 4:35 PM, Aaron MacDonald wrote:
> For some reason, the map function returns a list that has one more
> element than my input list.
>
> My input list is a range defined by [0, 60..359] (should translate
> into [0,60,120,180,240,300]).
>
> The function I'm giving to map is defined this way:
> -----
> degreesToRadians :: Double -> Double
> degreesToRadians degrees = degrees * (pi / 180)
> -----
>
> This is how I'm calling map overall:
> -----
> > map degreesToRadians [0,60..359]
> [0.0,1.0471975511965976,2.0943951023931953,3.141592653589793,4.1887902047863905,5.235987755982989,6.283185307179586
> ]
> -----
>
> As you can hopefully see, there are seven elements instead of six.
> Getting the length confirms this:
> -----
> > length [0,60..359]
> 6
> > length $ map degreesToRadians [0,60..359]
> 7
> -----
>
> I do not seem to get this behaviour with the length if I either
> substitute the degreesToRadians function or substitute the
> [0,60..359] range.
>
> P.S. Is there a built-in function to convert degrees to radians and
> vice-versa?
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
More information about the Beginners
mailing list