[Haskell-cafe] Haskell Propeganda

Ketil Malde ketil at malde.org
Thu Aug 28 02:40:42 EDT 2008


Aaron Tomb <atomb at galois.com> writes:

>> Huh? Type safety buys [...] nothing about dereferencing null
>> pointers, which are the moral equivalent of Nothing.

> What type safety buys you, in my mind, is that Nothing is only a valid
> value for explicit Maybe types. In cases where you don't use Maybe,
> the "null" situation just can't occur. In languages with null
> pointers, any pointer could possibly be null.

To write Haskell that is obviously safe, you need to check all cases
of algebraic data types - both Just and Nothing.
To do something similar in C, you need to check every pointer for NULL.  

The great thing about Maybe is that once I've checked it isn't
Nothing, I can extract the value and dispense with further checks.

  foo mbx = maybe default (bar x) mbx
  
Usually, you don't want to go on processing a NULL pointer anyway, but
in C, 'bar' might be called with NULL, so it'll have to check it
again.  And 'bar' is less likely than 'foo' to be able to do
anything sensible with NULL, and thus 'foo' needs to be able to handle
errors returned from 'bar', too.

I think an important reason we get NULL pointer SEGVs is that all this
checking when you "know" it can't happen gets tedious, and thus
ignored and forgotten.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell-Cafe mailing list