How about adding rational fraction to Python?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Feb 28 02:37:46 EST 2008


On Wed, 27 Feb 2008 19:00:19 -0800, Paul Rubin wrote:

> Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
>> Okay, that's just insane, making distinctions between literals and 
>> variables like that.
>> 
>> 1 + 1.0  # okay
> 
> => Yes
> 
>> x = 1
>> x + 1.0  # is this okay or not? who knows?
> 
> => Yes, ok
> 
>> len('s') + 1.0  # forbidden
> 
> Yes, forbidden.  
> 
> More examples:
> 
>    x = 1
>    y = len(s) + x
> 
> => ok, decides that x is an int
> 
>    x = 1
>    y = x + 3.0
> 
> => ok, decides that x is a float
> 
>    x = 1
>    y = x + 3.0
>    z = len(s) + x
> 
> => forbidden, x cannot be an int and float at the same time.
> 
>> I am so glad you're not the designer of Python.
> 
> This is how Haskell works and I don't notice much complaints about it.

Complain!  :-)

For implementing this in Python you have to carry an "is allowed to be
coerced to float" flag with every integer object to decide at run time if
it is an error to add it to a float or not.  Or you make Python into a
statically typed language like Haskell.  But then it's not Python anymore
IMHO.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list