[Haskell] Empty instance declaration

David Roundy daveroundy at gmail.com
Fri Dec 28 10:08:53 EST 2007

On Dec 27, 2007 2:20 PM, Jorge Marques Pelizzoni <jpeliz at icmc.usp.br> wrote:
> 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.

This is definitely not the same as detecting non-terminating programs,
it's a case of wanting to add expressiveness so that the "minimal
instance defines either show or showsPrec" could be placed in the code
instead of in haddock, and ghc could at minimum generate a warning in
this situation.  Class designers would be delighted to be able to add
this sort of information, and no longer have this tradeoff between
making it easy to write correct instances and making it hard to write
incorrect instances.

The trouble, of course, is that classes could have rather complicated
"minimum instance" requirements.  Still, if someone came up with a
decent syntax such as (but better than)

class Foo f where
   foo :: f
   foo = bar
   bar :: f
   bar = foo
  requiring ( foo || bar )

it would be very nice.  The trouble, of course, is deciding how
expressive to make the requirements.


More information about the Haskell mailing list