Against PEP 240

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue May 29 14:18:06 EDT 2001


Tue, 29 May 2001 14:12:38 +0200, Alex Martelli <aleaxit at yahoo.com> pisze:

> I'm not sure what various dialects of Lisp, Scheme, Prolog, Erlang,
> Haskell, and other non-classic languages do, but I'd bet that SOME
> of them take 7.35 as meaning 7.35 (aka 147/20, an exact rational
> number).

In Haskell it depends on the type as which the literal is used. It
can mean either exact Rational or inexact Float or Double or whatever
fractional type you define and use a literal as. It's specified as
applying the overloaded function fromRational to an exact rational;
an analogous mechanism is for integral literals (42 can be a Rational
or Double too, but also an Integer or Int). If the context doesn't
determine a type precisely, but requires that it's numeric, then the
type is defaulted. Types to which numeric types are defaulted are
specified per module. The default default is (Integer, Double), i.e.
Integer is tried first, then Double. Relying on defaulting is not a
good practice (ghc -Wall warns about it), it's better to specify the
type somewhere.

In Lisp (as an experiment shows, I don't have the specs) 7.35 is a
floating point number. Rational literals are written thus: 147/20,
and actual division thus: (/ 147 20), which yields 147/20, not 7.35.

I would prefer to have rationals by default and floating point when
requested (and to have integers which don't overflow by default).

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list