[Haskell-cafe] Shorthand method of enumerating a list a gotcha ... or is it just me?

Gene A yumagene at gmail.com
Fri May 7 18:05:20 EDT 2010


The problem I see is that in both:
 Version: September 2006 of hugs, which is the one that is current for
Ubuntu 9.10 release, and
ghci 6.10.4, they both exhibit a {I think} strange behaviour, in regards
to the shorthand way of calling out a list of enumerable values.  I will
explain the problem that I have run into with examples:

Hugs> [3,7..22]
[3,7,11,15,19]     <- OK

Hugs> map (* 1.0) [3,7,11,15,19]  <- manual spec OK
[3.0,7.0,11.0,15.0,19.0]

Hugs> map (* 1.0) [3,7..22]   <- same spec as first but !!! when
                                                mapped to with a (*1.0) to
coerce
                                                them to reals:
[3.0,7.0,11.0,15.0,19.0,23.0]   <- went one outside of range spec.

========================================
Exactly the same behaviour from ghci 6.10.4 :

Prelude> [3,7..22]
[3,7,11,15,19]

Prelude> map (* 1.0) [3,7..22]  <- using a range
[3.0,7.0,11.0,15.0,19.0,23.0]     <- it screws up
                                                 {at least it is not a
"feature' to me}

Prelude> map (* 1.0) [3,7,11,15,19]   <- spelled out it acts "right".
[3.0,7.0,11.0,15.0,19.0]

This seems like a possible bug? or at least a sure fire trap waiting to
be sprung ... one of those nasties that could really create havoc if
someone is not aware of this behaviour and buries a function that include
something that unwittingly coerces from an Integral to a Realfrac or
Fractional.  Is this a well known thing to watch out for..
or is it something that can be worked around, other then having to
enumerate every value in a list rather then use the handiness of
the range notation as shorthand?

cheers,

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


More information about the Haskell-Cafe mailing list