Circular Instance Declarations
Ashley Yakeley
ashley@semantic.org
Sat, 06 Sep 2003 22:56:47 -0700
When -fallow-undecidable-instances is switched on, is there any reason
why circular instances are forbidden? For instance:
module CircularInsts where
{
data D r = ZeroD | SuccD (r (D r));
instance (Eq (r (D r))) => Eq (D r) where
{
ZeroD == ZeroD = True;
(SuccD a) == (SuccD b) = a == b;
_ == _ = False;
};
newtype C a = MkC a deriving Eq;
equalDC :: D C -> D C -> Bool;
equalDC = (==);
}
When I compile this, I get this:
$ ghc -fglasgow-exts -fallow-undecidable-instances -c CircularInsts.hs
CircularInsts.hs:2:
Context reduction stack overflow; size = 21
Use -fcontext-stack20 to increase stack size to (e.g.) 20
`Eq (C (D C))' arising from use of `==' at CircularInsts.hs:16
`Eq (D C)' arising from use of `==' at CircularInsts.hs:16
`Eq (C (D C))' arising from use of `==' at CircularInsts.hs:16
`Eq (D C)' arising from use of `==' at CircularInsts.hs:16
Would it be reasonable for the compiler to check back through the stack
and allow the circularity? It will just create an ordinary recursive
function.
--
Ashley Yakeley, Seattle WA