Why a context reduction stack overflow?

Simon Peyton-Jones simonpj@microsoft.com
Fri, 1 Feb 2002 05:34:23 -0800


Mike

The interaction of functional dependencies with overlapping
instances is very uncharted territory, and I make no claims
about what GHC will do.  Overlapping instances in general
are a major problem.

You are on very very thin ice when you write
	instance P a b c =3D> P b a c

You'll send the type checker into a loop in a jiffy with something
like that.=20

I believe Thomas Hallgren had a paper about doing Peano=20
arithmetic in the class system, which is what you seem to be doing.

Simon


| -----Original Message-----
| From: Mike Gunter [mailto:m@ryangunter.com]=20
| Sent: 23 January 2002 23:00
| To: glasgow-haskell-users@haskell.org
| Subject: Why a context reduction stack overflow?
|=20
|=20
|=20
| Compilation, with ghc 5.02, of the following program:
|=20
|   data Zero   =3D Zero      deriving Show
|   data Succ a =3D Succ a    deriving Show
|  =20
|   -- Compilations succeeds with the following line uncommented.
|   -- t :: Succ Zero	--      =
<=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
|   t =3D Zero `p` (Succ Zero)
|  =20
|   class P a b c | a b -> c where
|     p :: a -> b -> c
|   instance            P Zero  a   a   where p Zero a =3D a
|   instance P a b c =3D> P b     a   c   where p b    a =3D p a b
|  =20
|   main =3D putStrLn $ "Hello."
|=20
| succeeds with the indicated line uncommented.  With it=20
| commented-out, the compilation fails with:
|=20
|   Flip.hs:6:
|       Context reduction stack overflow; size =3D 21
|       Use -fcontext-stack20 to increase stack size to (e.g.) 20
|       `P (Succ Zero) Zero c' arising from use of `p' at Flip.hs:6
|       `P Zero (Succ Zero) c' arising from use of `p' at Flip.hs:6
|       `P (Succ Zero) Zero c' arising from use of `p' at Flip.hs:6
|       `P Zero (Succ Zero) c' arising from use of `p' at Flip.hs:6=20
|=20
|        ...
|=20
|       `P (Succ Zero) Zero c' arising from use of `p' at Flip.hs:6
|       `P Zero (Succ Zero) c' arising from use of `p' at Flip.hs:6
|       `p at [Zero Succ Zero c]' arising from use of `p' at Flip.hs:6
|       When generalising the type(s) for t
|  =20
| .  Why?
|=20
|         thanks,
|         mike gunter
|=20
|=20
| _______________________________________________
| Glasgow-haskell-users mailing list=20
| Glasgow-haskell-users@haskell.org=20
| http://www.haskell.org/mailman/listinfo/glasgow-| haskell-users
|=20