# Why a context reduction stack overflow?

**Mike Gunter
**
m@ryangunter.com

*23 Jan 2002 15:00:02 -0800*

Compilation, with ghc 5.02, of the following program:
data Zero = Zero deriving Show
data Succ a = Succ a deriving Show
-- Compilations succeeds with the following line uncommented.
-- t :: Succ Zero -- <=============================
t = Zero `p` (Succ Zero)
class P a b c | a b -> c where
p :: a -> b -> c
instance P Zero a a where p Zero a = a
instance P a b c => P b a c where p b a = p a b
main = putStrLn $ "Hello."
succeeds with the indicated line uncommented. With it commented-out,
the compilation fails with:
Flip.hs:6:
Context reduction stack overflow; size = 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
...
`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
. Why?
thanks,
mike gunter