[Haskell-cafe] Why does [1.0, 3 ..4] contain 5?

Silvio Frischknecht silvio.frischi at gmail.com
Wed Oct 19 19:21:26 UTC 2016


Sorry I must be a bit tired :)


On 10/19/2016 09:16 PM, Silvio Frischknecht wrote:
> Hi,
>
> I don't claim to know the real reason. But I can see that it would make
> some things more stable or rather it makes the stable versions look nicer.
>
> [1,1.1 .. 2] looks better than
> [1,1.1 .. 2.05]
>
> If you define it like you suggest
>
> numericEnumFromThenTo e1 e2 e3 = takeWhile (<=e1) [e2, e3 ..] :: [Float]
numericEnumFromThenTo e1 e2 e3 = takeWhile (<=e3) [e1, e2 ..] :: [Float]
>
> I get
>
> length $ numericEnumFromThenTo 1 1.1 2 === 10
> length $ numericEnumFromThenTo 2 1.2 3 === 11
length $ numericEnumFromThenTo 2 2.1 3 == 11
>
>
>
> Cheers,
> Silvio
>



More information about the Haskell-Cafe mailing list