[Haskell-cafe] Haskell Propeganda

Tim Docker timd at macquarie.com.au
Wed Aug 27 21:13:35 EDT 2008

Dan Weston wrote: 

> Tim Docker wrote:
> > That differs from my experience. Most segfaults that *I've* caused
> > C or C++) have been due to dereferencing null pointers. Type safety 
> > does help you here, in that Maybe lets you distinguish the types of 
> > things that are optionally present from those that must be.
> Huh? Type safety buys you not having to worry about dereferencing
stale nonnull
> pointers (lifetime of reference exceeding lifetime of referent), but
> about dereferencing null pointers, which are the moral equivalent of
> Failure to handle a null pointer is just like using fromJust and
results in
> the same program termination (undefined).

Well as someone else pointed out, you can reliably catch a pattern match
failure. You may or may not be able to catch a segfault.

But my point is that haskell trivially lets you distinguish between
values (type X),
and nullable values (type Maybe X), and doing so is standard practice
when using
the language. The compiler will disallow any inconsistency in the use of
these two

C however, does not have a compile time distinction between a pointer to
a value
that might be null, and one that is guaranteed not to be null. The code
must track this distinction manually. Mistakes result in segvs, not
compile errors.


More information about the Haskell-Cafe mailing list