Circular Instance Declarations
Simon Peyton-Jones
simonpj@microsoft.com
Thu Sep 11 15:23:03 EDT 2003
OK, I yield!
The HEAD now runs this program. It turned out to be a case of
interchanging two lines of code, which is the kind of fix I like.
Simon
| -----Original Message-----
| From: haskell-admin@haskell.org [mailto:haskell-admin@haskell.org] On
Behalf Of Ashley Yakeley
| Sent: 07 September 2003 06:57
| To: haskell@haskell.org
| Subject: Circular Instance Declarations
|=20
| When -fallow-undecidable-instances is switched on, is there any reason
| why circular instances are forbidden? For instance:
|=20
| module CircularInsts where
| {
| data D r =3D ZeroD | SuccD (r (D r));
|=20
| instance (Eq (r (D r))) =3D> Eq (D r) where
| {
| ZeroD =3D=3D ZeroD =3D True;
| (SuccD a) =3D=3D (SuccD b) =3D a =3D=3D b;
| _ =3D=3D _ =3D False;
| };
|=20
| newtype C a =3D MkC a deriving Eq;
|=20
| equalDC :: D C -> D C -> Bool;
| equalDC =3D (=3D=3D);
| }
|=20
| When I compile this, I get this:
|=20
| $ ghc -fglasgow-exts -fallow-undecidable-instances -c
CircularInsts.hs
| CircularInsts.hs:2:
| Context reduction stack overflow; size =3D 21
| Use -fcontext-stack20 to increase stack size to (e.g.) 20
| `Eq (C (D C))' arising from use of `=3D=3D' at =
CircularInsts.hs:16
| `Eq (D C)' arising from use of `=3D=3D' at CircularInsts.hs:16
| `Eq (C (D C))' arising from use of `=3D=3D' at =
CircularInsts.hs:16
| `Eq (D C)' arising from use of `=3D=3D' at CircularInsts.hs:16
|=20
| 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.
|=20
| --
| Ashley Yakeley, Seattle WA
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org
| http://www.haskell.org/mailman/listinfo/haskell
More information about the Haskell
mailing list