[Haskell-beginners] Context reducion Stack overflow

Marco Túlio Gontijo e Silva marcot at holoscopio.com
Mon May 4 10:59:54 EDT 2009


Hello,

I'm trying to compile the following code:

> import Data.IORef

> class F f where
>   m :: (a -> a) -> f a -> f a

> class M m a where
>   mm :: (a -> a) -> m -> IO ()

> instance (F f, M m (f a)) => M m a where
>   mm f v = mm (m f) v

And I'm getting:

$ ghci teste.lhs -XMultiParamTypeClasses -XFlexibleInstances
-XFlexibleContexts -XUndecidableInstances -XIncoherentInstances

GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Failed, modules loaded: none.
Prelude> ^DLeaving GHCi.
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( teste.lhs, interpreted )

teste.lhs:1:0:
    Context reduction stack overflow; size = 20
    Use -fcontext-stack=N to increase stack size to N
        `$dM{atp} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f
(f (f (f (f a))))))))))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{atm} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f
(f (f (f a)))))))))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{atj} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f
(f (f a))))))))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{atg} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f
(f a)))))))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{atd} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f
a))))))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{ata} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f (f (f (f
a)))))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{at7} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f (f (f
a))))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{at4} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f (f
a)))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{at1} :: {M m
                        (f (f (f (f (f (f (f (f (f (f (f (f
a))))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asY} :: {M m (f (f (f (f (f (f (f (f (f (f (f
a)))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asV} :: {M m (f (f (f (f (f (f (f (f (f (f a))))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asS} :: {M m (f (f (f (f (f (f (f (f (f a)))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asP} :: {M m (f (f (f (f (f (f (f (f a))))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asM} :: {M m (f (f (f (f (f (f (f a)))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asJ} :: {M m (f (f (f (f (f (f a))))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asG} :: {M m (f (f (f (f (f a)))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asD} :: {M m (f (f (f (f a))))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asA} :: {M m (f (f (f a)))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asx} :: {M m (f (f a))}'
          arising from a use of `mm' at teste.lhs:10:13-22
        `$dM{asj} :: {M m (f a)}'
          arising from a use of `mm' at teste.lhs:10:13-22
Failed, modules loaded: none.

An example of instances of these classes:
> instance F [] where
>   m = map

> instance M (IORef a) a where
>   mm = flip modifyIORef

I don't get what's the problem with my definition.  Can someone clarify
me on this?

Greetings.
-- 
marcot
http://marcot.iaaeee.org/




More information about the Beginners mailing list