[Haskell-cafe] Re: Debugging partial functions by the rules

Jan-Willem Maessen jmaessen at alum.mit.edu
Wed Nov 15 17:11:36 EST 2006

On Nov 15, 2006, at 3:21 AM, oleg at pobox.com wrote:

> Donald Bruce Stewart wrote:
>> So all this talk of locating head [] and fromJust failures got me
>> thinking:
>>     Couldn't we just use rewrite rules to rewrite *transparently*
>>     all uses of fromJust to safeFromJust, tagging the call site
>>     with a location?
> I'm sorry for shifting the topic: I'm wondering if, rather than trying
> to make an error message more informative, we ought to make sure that
> no error will ever arise?
> ...
> This topic has been discussed at length on this list. It seems that
> the discussion came to the conclusion that eliminating head of
> the empty list error is possible and quite easy in Haskell.
>   http://www.haskell.org/pipermail/haskell-cafe/2006-September/ 
> 017915.html

But this code contains a function with_non_empty_list (or perhaps  
with_nonempty_list or withNonemptyList or...) which has the same  
confusing failure mode as the examples under discussion.   
Fundamentally, if we try to package up "check for failure" in a  
function, whether the function does something useful as well (head,  
tail, fromJust) or not (withNonemptyList), we miss out on useful  
contextual information when our program fails.

In addition, we have this rather nice assembly of functions which  
work on ordinary lists.  Sadly, rewriting them all to also work on  
NonEmptyList or MySpecialInvariantList is a nontrivial task.

Which isn't to say that I disapprove of this style: check your  
invariants early, maintain them as you go.  I'm quite enjoying the  
escH paper, but I get through about a column per day between  
compiles. :-)

-Jan-Willem Maessen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2425 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061115/f714a7f5/smime.bin

More information about the Haskell-Cafe mailing list