ghc6 behavior with circular instance declaration
Simon Peyton-Jones
simonpj at microsoft.com
Thu Oct 23 10:57:33 EDT 2003
| -- convententionally, we write:
| {-
| instance (Myeq a) => Myeq [a] where
| myeq (x:xs) (y:ys) = (myeq x y)&&(myeq xs ys)
| -}
|
| instance (Myeq a,Myeq [a]) => Myeq [a] where
| myeq (x:xs) (y:ys) = (myeq x y)&&(myeq xs ys)
|
|
|
| I want to make the 2nd call of myeq to be of an
| instance function from the context instead of a
| recursive call. And obviously there is an obvious
| cycle in the instances declaration.
I don't know why you would possibly want this.
So far as I can see from your message, the recursive dictionary
you are trying to build is exactly the same as what GHC will build
automatically from the "conventional" instance declaration.
| I run it in ghc6.0.1, it is reported well-typed, but
| when I run it with some arguments, I get a run-time
| error.
|
| Loading package base ... linking ... done.
| Compiling Myeq ( Myeq.hs, interpreted )
| Ok, modules loaded: Myeq.
| *Myeq> myeq [] []
|
| Context reduction stack overflow; size = 21
You must have use -fallow-undecidable-instances,
and if you do that, you risk divergence. It's really
not clear what you expect to happen.
Simon
More information about the Haskell
mailing list