On Mon, Feb 2, 2015 at 5:07 PM, Paul Rubin <no.email@nospam.invalid> wrote:
> Chris Angelico <ros...@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
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to