Not logged in
Log in now
Create an account
Subscribe to LWN
Pencil, Pencil, and Pencil
Dividing the Linux desktop
LWN.net Weekly Edition for June 13, 2013
A report from pgCon 2013
Little things that matter in language design
Yup. You learn Haskell and/or ML (and/or ...) and the case against null pointers becomes so obvious you don't even know how to explain it.
RE: nullable pointers
Posted Apr 1, 2011 9:12 UTC (Fri) by paulj (subscriber, #341)
If you specifically mean SEGVs, well that's very easy to explain: Haskell and functional languages generally do not have pointers.
Posted Apr 1, 2011 21:01 UTC (Fri) by mathstuf (subscriber, #69389)
safeHead :: [a] -> Maybe a
safeHead  = Nothing
safeHead (a:_) = Just a
When calling safeHead, the caller must* check to see if a value was actually returned before using it. This can be done with fromMaybe:
fromMaybe sensibleDefault $ safeHead someList
* The caller can just use fromJust which raises an exception on a Nothing value, but that's the caller's burden at that point.
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds