12 ms·
Functional languages like ML and Haskell use option types instead of nulls, and they have tools to work with option types that go far beyond what most languages
by chc 16y ago
Functional languages like ML and Haskell use option types instead of nulls, and they have tools to work with option types that go far beyond what most languages have for nulls. For example, in Haskell, that chain of function calls might be written like this:
find "table" [("class", "search-params")] soup >>=
findParent "form" >>=
find "td" [("class", "elem")] >>=
find "input" [] >>=
get "name"
If the result of any call in the chain is Nothing (equivalent to null), we get Nothing. Otherwise, it keeps on going and (if, for example, the name of the relevant element is "signup") we get Just "signup".
Simulating Haskell's option type is actually the article's proposed solution.