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 => P b a c
You'll send the type checker into a loop in a jiffy with something
like that.
I believe Thomas Hallgren had a paper about doing Peano
arithmetic in the class system, which is what you seem to be doing.
Simon
| -----Original Message-----
| From: Mike Gunter [mailto:[EMAIL PROTECTED]]
| Sent: 23 January 2002 23:00
| To: [EMAIL PROTECTED]
| Subject: Why a context reduction stack overflow?
|
|
|
| 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
|
|
| _______________________________________________
| Glasgow-haskell-users mailing list
| [EMAIL PROTECTED]
| http://www.haskell.org/mailman/listinfo/glasgow-| haskell-users
|
_______________________________________________
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users