[Haskell-cafe] instance Enum Double considered not entirelygreat?
Richard O'Keefe
ok at cs.otago.ac.nz
Tue Sep 27 06:24:46 CEST 2011
On 27/09/2011, at 3:54 PM, Donn Cave wrote:
> Quoth "Richard O'Keefe" <ok at cs.otago.ac.nz>,
>
> [ ... re " Why would you write
> an upper bound of 0.3 on a list if you don't expect that to be included
> in the result? " ]
>
>> Because upper bounds are *UPPER BOUNDS* and are NOT as a rule included
>> in the result. If you write [0,2..9] you
>> - DO expect 0 in the result
>> - DON'T expect 9 in the result
>> - would be outraged if 10 were in the result.
>
> Pardon the questions from the gallery, but ... I can sure see that
> 0.3 shouldn't be included in the result by overshooting the limit
> (i.e., 0.30000000000000004), and the above expectations about
> [0,2..9] are obvious enough, but now I have to ask about [0,2..8] -
> would you not expect 8 in the result? Or is it not an upper bound?
Quoting the Wikipedia:
In mathematics, especially in order theory,
an upper bound of a subset S of some partially ordered set (P, ≤)
is an element of P which is greater than or equal to
every element of S. ^^^^^^^^^^^
In the case of integers, where is the overshoot?
I expect [L,M..U] to be the collection of all x
such that L <= x <= U and x-L is n*(M-L) for some
n, if M >= L, or the collection of all x such that
U <= x <= L and x-L is n*(M-L) for some n, if M <= L.
I don't say that's what Haskell promises. What I say
is that that's what I _expect_. On the rare occasions
when I've used REAL DO, getting close to the stated
end point has been unimportant; not going outside the
stated bounds critically important.
In the case of [0,2..8], 0 <= 8 <= 8 and 8-0 is 4*(2-0),
so 8 should be there.
[0,1/10..3/10] :: [Ratio Int] includes 3/10 as it should;
3/10 <= 3/10 so that's fine too.
More information about the Haskell-Cafe
mailing list