10Pines / pdepreludat

BSD 3-Clause "New" or "Revised" License
24 stars 2 forks source link

Fixes #15 - Comportamiento del enum from then to #27

Closed JuanFdS closed 3 years ago

JuanFdS commented 3 years ago

Problem

The behaviour of lists defined with range syntax is not obvious when using decimal numbers in Haskell, and since the PdePreludat uses decimal values for all numbers this behaviour happened even if all the numbers in the list where integers:

image

Why this happens?

It's explained in this spec: https://www.haskell.org/onlinereport/basic.html,

 For the types Int and Integer, the enumeration functions have the following meaning:

    The sequence enumFrom e1 is the list [e1,e1+1,e1+2,...].

    The sequence enumFromThen e1 e2 is the list [e1,e1+i,e1+2i,...], where the increment, i, is e2-e1. The increment may be zero or negative. If the increment is zero, all the list elements are the same.

    The sequence enumFromTo e1 e3 is the list [e1,e1+1,e1+2,...e3]. The list is empty if e1 > e3.

    The sequence enumFromThenTo e1 e2 e3 is the list [e1,e1+i,e1+2i,...e3], where the increment, i, is e2-e1. If the increment is positive or zero, the list terminates when the next element would be greater than e3; the list is empty if e1 > e3. If the increment is negative, the list terminates when the next element would be less than e3; the list is empty if e1 < e3. 

For Float and Double, the semantics of the enumFrom family is given by the rules for Int above, except that the list terminates when the elements become greater than e3+i/2 for positive increment i, or when they become less than e3+i/2 for negative i.

EnumFromThenTo generates values in the list not until there's a value higher/lower than the last parameter, but when it gets a value that is at more than half a step of distance from that last parameter.

Solution

Keep the same behaviour for decimals because it could make sense when dealing with rounding and also to keep the PdePreludat similar to Prelude there. However, when all the parameters are integers (have an empty decimal part) then have enumFromThenTo behave as it behaves for integers.

Juancete commented 3 years ago

<3

@Juancete!! Mirá que lindo fix!

Excelenteeeeeee!!!!