HELP: restore my faith in Python

Michael Hudson mwh21 at
Sat Mar 4 15:46:36 CET 2000

Moshe Zadka <moshez at> writes:
> [Tim Peters]
> > At the level of the original poster's question, the best IEEE-754
> > conformant answer is "floating point sucks".
> That's it. I've given up on trying to understand you. What should 
> 1/2 do?
> 1. It can't return 0.5 -- floating point sucks
> 2. It can't return Rational(1, 2) -- rational arithmetic blows up
> 3. It can't return 0 -- integer division is confusing
> (Note that I do agree on 1 and 3, and you managed to convince me about 2)
> i-fear-the-decimal-point-ly y'rs, Z.

In Haskell it doesn't work:

Main> tryme 1 2 where tryme :: Int -> Int -> Int; tryme a b = a / b
ERROR: Illegal Haskell 98 class constraint in inferred type
*** Expression : let {...} in tryme 1 2
*** Type       : Fractional Int => Int

The example's a bit contorted because literals *do* get promoted, but
the message is: don't divide `Int's.  I think the philosohpy is less
of the principle of least surprise, more of the principle of early
errors, i.e. (/) isn't really meaningful for integers (as you pointed
out) so it's best not to allow it at all - you have to say what you
mean if you want to do this.

Not an option for the programming language that wants to become part
of CP4E, probably.


very few people approach me in real life and insist on proving they are
drooling idiots.                         -- Erik Naggum, comp.lang.lisp

More information about the Python-list mailing list