[Haskell-cafe] Non-termination due to context

Emil Axelsson emax at chalmers.se
Fri Jan 22 07:38:06 EST 2010

Ross Paterson skrev:
> On Fri, Jan 22, 2010 at 12:24:37PM +0100, Emil Axelsson wrote:
>> Consider the following program:
>>> {-# LANGUAGE FlexibleInstances, OverlappingInstances, UndecidableInstances #-}
>>> class B a => A a
>>> instance A Int
>>> class Eq a => B a
>>> instance (A a, Eq a) => B a
>> [...]
>> Although I don't know all the details of the class system, it seems
>> unintuitive that I can make a program non-terminating just by
>> changing the context of a function (regardless of
>> UndecidableInstances etc.).
>> Is this a bug or a feature?
> I'm afraid you voided the warranty when you used UndecidableInstances.
> You really do have a circularity between A and B here, so it's not
> surprising that you get a loop.  By changing the context, you demanded
> more instances, undecidable ones in fact.

But still, I've always heard that "undecidable instances can cause the 
type checker to loop, but if the compiler terminates, you're fine". Here 
the loop happens at run time, so undecidable instances must be a little 
more evil than I thought...

/ Emil

More information about the Haskell-Cafe mailing list