[Haskell] Empty instance declaration

Jorge Marques Pelizzoni jpeliz at icmc.usp.br
Thu Dec 27 14:20:12 EST 2007

> instance Show WeekDay where
> (empty)

You see, an empty instance like that may serve various purposes. In
type-level programming, for example, they (roughly) correspond to facts in
logic programming. However, in the case at hand, this is what happens: the
doc for class Show reads thus:

"Minimal complete definition: showsPrec or show."

This (especially the word "or") means two things: (i) the class provides
default definitions for its functions; (ii) the default definition for
showsPrec (resp. show) is itself defined in terms of show (resp.

The problem is, when you declare an empty instance, all functions (if any)
assume their default definitions. Therefore, when you call show/showsPrec
(even indirectly) you end up in an endless loop because of (ii).

I agree with you that it'd be best if this sort of thing were detected at
compile time, but it ultimately boils down to automatically detecting
non-terminating programs... By the way, I haven't heard of a language that
tackles the same problem differently.



> Then he complained about getting  *** Exception: stack overflow when he
> tried to invoke some function on that type.
> After checking the Haskell98 grammar I found out that this is allowed
> syntactically and probably semantically too. Is there any reason to do
> that?
> Now I'm wondering: Shouldn't a class be an warranty of a well defined
> interface? Thus forcing the user to define the show function or showPrec?
> Am
> I missing any point?
> My best regards,
> Hugo
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell

Jorge M. Pelizzoni
ICMC - Universidade de São Paulo

More information about the Haskell mailing list