int to float problem (resend with addendum)

b.i.mills@massey.ac.nz b.i.mills@massey.ac.nz
Thu, 6 Mar 2003 15:02:54 +1300


  I just fluffed the To: field in the header, so my previous
  message was bounced, I'm resending this ... sorry if it
  turns up twice. (I also took the opportunity to make an addendum).

Yo,

> Haskell Integers are not a proper subset of Haskell Floats or
> Doubles.  Haskell does not support real numbers.

I'd just like to add ...

Real numbers are not implementable on a digital computer. This
is not a "practical" matter of resources, or a design decision
in by the language designer, but the fact that any data type 
each of whose elements are represented in a finite number of 
bytes can't have more than a countable number of data elements. 
Integers, and Rationals can be represented. Even the so-called 
computable-real-numbers, (still countable) don't work as well 
as you would want, since things such as "is this number bigger 
than that one" can't always be computed.

Add to this the fact that the generic float type does not 
satisfy algebraic constraints such as associativity, and so 
can't, from the axiomatic point of view, be considered to be 
a representation of rational numbers (let alone reals).

Basically, from the algebraic perspective, the float type is
a messy fudge, and does not fit in nicely with any of the 
"pure" types. In general the containment 

Complex ---> Real --> Rational ---> integer ---> whatever.

Does not apply in this simple way to numerical types on a
computer, because data types are often constructed on the
basis of not just what they represent, but also how they
represent these things. The computable world (constructive
mathematics) is a lot more complicated and open ended than
the existential approach.

Regards,

Bruce.

ps: I've made previous comments about this sort of thing:

``Algebraic Conversions'', A mathematical paper introducing
a generalisation of homomorphism of universal algebras.
In Research Letters in the Information and Mathematical
Sciences Vol 2, May 2001. (pub by Massey University New Zealand).
see also, \verb|http://www.massey.ac.nz/~wwiims/rlims|

Addendum: Personally I think that lattices of extension fields
          of the rationals give a good model for understanding
          what is going on with pure numerical types on digital
          computers, but maybe that's just me?