<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.5346.5" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>&gt; From: Robert Dockins &lt;<A 
href="mailto:robdockins@fastmail.fm">robdockins@fastmail.fm</A>&gt;<BR></DIV>
<DIV>&gt; It seems to me that every possible use of a partial function has 
some&nbsp; <BR>&gt; (possibly imagined) program invariant that prevents it from 
failing.&nbsp;&nbsp; <BR>&gt; Otherwise it is downright wrong.&nbsp; 'head', 
'fromJust' and friends&nbsp; <BR>&gt; don't do anything to put that invariant in 
the program text.<BR></DIV>
<DIV>Well, not really. For example, I often write programs with command line 
arguments, that contain code of the form</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Courier New">&nbsp;&nbsp;&nbsp; do ...</FONT></DIV>
<DIV><FONT face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[a,b] 
&lt;- getArgs</FONT></DIV>
<DIV><FONT 
face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>Of course the pattern match is partial, but if it&nbsp;fails, then the 
standard error message is good enough.</DIV>
<DIV>&nbsp;</DIV>
<DIV>This applies to "throw away" code, of course, and if I decide to keep the 
code then I sooner or later extend it to fix the partiality and give a more 
sensible error message.&nbsp;But it's still an advantage to be&nbsp;ABLE to 
write the more concise, but cruder version initially.</DIV>
<DIV>&nbsp;</DIV>
<DIV>This isn't a trivial point. We know that error handling code&nbsp;is a 
major&nbsp;part of&nbsp;software cost--it can even dominate the cost of the 
"correct case" code (by a large factor).&nbsp;Erlang's "program for the correct 
case" strategy, coupled with good fault tolerance mechanisms, is one reason for 
its commercial success--the cost of including error handling code *everywhere* 
is avoided. But&nbsp;this means accepting that code *may*&nbsp;very well 
fail--the failure is just going to be handled somewhere else.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Haskell (or at least GHC)&nbsp;has good exception handling mechanisms too. 
We should be prepared to use them, and "let it fail" when things&nbsp;go wrong. 
The savings of doing so are too large to ignore.</DIV>
<DIV>&nbsp;</DIV>
<DIV>John&nbsp;</DIV>
<DIV><FONT face="Courier New"></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV></BODY></HTML>