Python is DOOMED! Again!

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon Feb 2 00:19:37 EST 2015


Steven D'Aprano wrote:
> If I have an arbitrary pointer, and I want to check if it is safe to
> dereference, how do I do it? Surely I'm not expected to write something
> like:
> 
> if type(ptr) == A:
>     if ptr != Anil: ...
> if type(ptr) == B:
>     if ptr != Bnil: ... 
> 
> etc. That would be insane. So how does Haskell do this?

In Haskell you would just go ahead and compare ptr
with Nothing (or more likely pattern-match it against
Nothing).

Haskell knows the type of the thing you're comparing
to, and uses type inference to select the right type
of Nothing to use.

BTW, technically, Nothing isn't really a null
pointer, it's a member of an algebraic type
defined in the standard library:

data Maybe a = Just a | Nothing

So conceptually, there is a different Nothing for
each possible type 'a' in Maybe a. But since
the Nothing constructor doesn't have any arguments,
the implementation could represent them all by
the same value if it wanted.

-- 
Greg



More information about the Python-list mailing list