[Haskell-cafe] Re: Type question in instance of a class

Janis Voigtlaender voigt at tcs.inf.tu-dresden.de
Sun Nov 23 02:43:21 EST 2008

Henning Thielemann wrote:
> On Sat, 22 Nov 2008, Janis Voigtlaender wrote:
>> Definitely. And that surfaces even in quite innocently looking programs
>> and statements about them. The introductory example of the following
>> technical report may be amusing in that respect:
>> http://wwwtcs.inf.tu-dresden.de/~voigt/TUD-FI08-08.pdf
> In example 1, I don't see on the one hand, why 'takeWhile (null.tail)' 
> could fail with "tail: empty list",

Because the (GHC) semantics described in the following paper:


says so.

You can also check it by calculating with the definitions from Section 3
and Figure 8 of the above technical report. Or see it demonstrated on
slide pages 32-38 of:


> since all lists in '[[i] | i <- 
> [1..(div 1 0)]]' are non-empty (namely singletons).

This does not really have anything to do with the above, but I may just
as well say that all lists in '[[i] | i <- [1..(div 1 0)]]' are empty.
Or that they are all of length 17. Because there are no lists in '[[i] |
i <- [1..(div 1 0)]]'. (Note that the "supply" [1..(div 1 0)] is itself
erroneous.) The "tail: empty list" failure mentioned above really has
nothing at all to do with the concrete expression '[[i] | i <- [1..(div
1 0)]]'. Any other erroneous expression, such as just 'error "div-by-0"'
would lead to the same result.

> On the other hand, 
> aren't those imprecise error problems not just proofs that mixing up 
> errors and exceptions (here treating errors as exceptions) is a bad 
> thing? 'error' is only a candy version of 'undefined' for simplifying 
> debugging. If all 'error's are replaced by 'undefined' (plain bottom) 
> then 'takeWhile p (map h l)' and 'map h (takeWhile (p.h) l)' behave also 
> visually identical, don't they?

Yes, if all 'error's are replaced by 'undefined', then the two
expressions are semantically equivalent. But I don't buy this as a
decisive argument in the "errors vs. exceptions" debate.

Ciao, Janis.

Dr. Janis Voigtlaender
mailto:voigt at tcs.inf.tu-dresden.de

More information about the Haskell-Cafe mailing list