Enum class

John Meacham john@repetae.net
Tue, 23 Oct 2001 02:47:20 -0700


On Tue, Oct 23, 2001 at 07:32:58PM +1000, Tim Barbour wrote:
> Lennart Augustsson writes:
>  > "Ch. A. Herrmann" wrote:
>  > 
>  > > (1) What is the justification for the types "Float" and "Double"
>  > >     to be members of the type class "Enum"? This might induce students
>  > >     to use floating point values as counters in arithmetic
>  > >     sequences.
>  > 
>  > And what's wrong with that? If the students are using are using values
>  > like 0.1 and expecting it to be represented exactly then they should have
>  > some lectures about floating point arithmetic.
> 
> Real numbers (which floating point numbers are trying to be) are not enumerable
> (that is, they cannot be placed in a one-one correspondence with the integers).
> 
>  > I've heard your complaint before, but I can't really understand why removing
>  > Float and Double from Enum would make Haskell any better for beginners.
>  > These two type  have complicated properties, and to use them correctly you
>  > have to know about them.  It's something you have to learn sooner or later.
>  > (In the the olden day when I had my first CS course we were told about it
>  > very early.)
> 
> I don't see it as a matter of ease of understanding for beginners. How can
> floating point numbers be meaningfully enumerated (they could be enumerated by
> treating their binary representation as an integer, but that is not meaningful)
> ? What is the "successor" of pi ?

I think the problem is that Enum in haskell means not only enumerable
types, but types which have enumerable subsets when taken with an
incrementer. which the reals satisfy. this can be demonstrated by things
like [1.0, 1.1 ..]  which is obviously equinumerous to the integers. I
think the confusion comes from the fact that Enum is a misnomer, it does
not necisarilly imply the type is countable, just that we can create
meaningful countable subsets....  now whether that is a good idea is a
different question.

	John


-- 
---------------------------------------------------------------------------
John Meacham - California Institute of Technology, Alum. - john@repetae.net
---------------------------------------------------------------------------