RE: ghc6 behavior with circular instance declaration
| -- 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
Hi Simon, --- Simon Peyton-Jones <simonpj@microsoft.com> wrote:
I don't know why you would possibly want this.
yes, in this example there isn't any obvious reason to motivate us writing such instance, but I am interested in how GHC now handles coinduction in type class. It will be neat if we can express coinductive algorithm in terms of Haskell type class. Currently I am working a project with Dr Martin Sulzmann in which we think such an extension is neccessary.
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. Yes, exactly, I realized that after I compiled the code with -fext-core flag. Is it because it tries to avoid building infinite evidence constructors?
Thanks for pointing out. Regards, Kenny LU Zhuo Ming Research Assistant School of Computing National University of Singapore __________________________________________________ Do You Yahoo!? Faster. Easier. Bingo. http://sg.search.yahoo.com
participants (2)
-
Kenny -
Simon Peyton-Jones