[Haskell-cafe] Haskell Propeganda
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
> 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
> 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
the language. The compiler will disallow any inconsistency in the use of
C however, does not have a compile time distinction between a pointer to
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
More information about the Haskell-Cafe