October 2015
Beginner to intermediate
400 pages
14h 44m
English
A function can return more than one result. We’ve seen many examples of functions from standard packages that return two values, the desired computational result and an error value or boolean that indicates whether the computation worked. The next example shows how to write one of our own.
The program below is a variation of findlinks that makes the
HTTP request itself so that we no longer need to run fetch.
Because the HTTP and parsing operations can fail,
findLinks declares two results: the list of discovered links
and an error.
Incidentally, the HTML parser can usually recover from bad input and
construct a document containing error nodes, so Parse rarely fails; when it does, it’s typically due to underlying ...