Python is DOOMED! Again!

Chris Angelico rosuav at gmail.com
Mon Feb 2 01:16:08 EST 2015


On Mon, Feb 2, 2015 at 5:07 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> Chris Angelico <rosuav at gmail.com> writes:
>> So since you can set something to Nothing regardless of type, and
>> compare it against Nothing regardless of type, it doesn't really much
>> matter that there are different types of Nothing. Right?
>
> No that's not how type inference works.  If you have x = Nothing and
> pass it to a function that takes a Maybe Int, type inference means the
> compiler figures out that x must have type Maybe Int.  If you then also
> pass x to something that takes Maybe String, you are telling the
> compiler that x has two different types at the same time, so the
> compiler reports a type error.

If you say "x = 5" and pass it to a function that accepts "Int or
String", the compiler knows that it's actually an Int. If you then
also pass that x to something that takes "Int or List", is that legal?
If so, then 5 is separate from the "or String" and "or List" parts,
and Nothing is actually typed. If not, then it's x, not Nothing, that
has the type.

ChrisA



More information about the Python-list mailing list