Failed to satisfy superclass

I have the following code and I cannot figure out why I am getting the first error shown below. As far as I can tell, the copy MonadState

should be satisfied. Even when I explicitly add an instance "non-output" character for the character in the instance constraint, I still get the error. This is mistake? How can I solve this problem?

Windows GHC version 7.8.3

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}

module Test where

import Control.Applicative
import Control.Lens
import Control.Lens.Internal.Zoom
import Control.Monad.State


newtype Engine st m a = Engine {
    unEngine :: StateT st m a
} deriving (Functor, Applicative, Monad, MonadState st, MonadTrans, MonadIO)


type instance Zoomed (Engine st m) = Focusing m


-- Same error message even with: (Monad m, MonadState st' (Engine st' m)) =>
instance (Monad m) => Zoom (Engine st m) (Engine st' m) st st' where
    zoom l = Engine . zoom l . unEngine

      


Test.hs:22:10:
    Could not deduce (mtl-2.1.3.1:Control.Monad.State.Class.MonadState
                        st' (Engine st' m))
      arising from the superclasses of an instance declaration
    from the context (Monad m)
      bound by the instance declaration at Test.hs:22:10-62
    In the instance declaration for
      Zoom (Engine st m) (Engine st' m) st st'

Test.hs:23:23:
    Could not deduce (Zoomed (StateT st' m) ~ Focusing m)
    from the context (Zoomed (Engine st m) ~ Zoomed (Engine st' m),
                      mtl-2.1.3.1:Control.Monad.State.Class.MonadState st (Engine st m),
                      mtl-2.1.3.1:Control.Monad.State.Class.MonadState
                        st' (Engine st' m),
                      Monad m)
      bound by the instance declaration at Test.hs:22:10-62
    Relevant bindings include
      l :: LensLike' (Zoomed (Engine st m) c) st' st
        (bound at Test.hs:23:10)
      zoom :: LensLike' (Zoomed (Engine st m) c) st' st
              -> Engine st m c -> Engine st' m c
        (bound at Test.hs:23:5)
    In the first argument of `(.)', namely `zoom l'
    In the second argument of `(.)', namely `zoom l . unEngine'
    In the expression: Engine . zoom l . unEngine

Test.hs:23:23:
    Could not deduce (Zoom (StateT st m) (StateT st' m) st st')
      arising from a use of `zoom'
    from the context (Zoomed (Engine st m) ~ Zoomed (Engine st' m),
                      mtl-2.1.3.1:Control.Monad.State.Class.MonadState st (Engine st m),
                      mtl-2.1.3.1:Control.Monad.State.Class.MonadState
                        st' (Engine st' m),
                      Monad m)
      bound by the instance declaration at Test.hs:22:10-62
    In the first argument of `(.)', namely `zoom l'
    In the second argument of `(.)', namely `zoom l . unEngine'
    In the expression: Engine . zoom l . unEngine

Test.hs:23:28:
    Could not deduce (Zoomed (StateT st m) ~ Focusing m)
    from the context (Zoomed (Engine st m) ~ Zoomed (Engine st' m),
                      mtl-2.1.3.1:Control.Monad.State.Class.MonadState st (Engine st m),
                      mtl-2.1.3.1:Control.Monad.State.Class.MonadState
                        st' (Engine st' m),
                      Monad m)
      bound by the instance declaration at Test.hs:22:10-62
    Expected type: LensLike' (Zoomed (StateT st m) c) st' st
      Actual type: LensLike' (Zoomed (Engine st m) c) st' st
    Relevant bindings include
      l :: LensLike' (Zoomed (Engine st m) c) st' st
        (bound at Test.hs:23:10)
      zoom :: LensLike' (Zoomed (Engine st m) c) st' st
              -> Engine st m c -> Engine st' m c
        (bound at Test.hs:23:5)
    In the first argument of `zoom', namely `l'
    In the first argument of `(.)', namely `zoom l'

      

+3


source to share


1 answer


Your code works for me, also GHC 7.8.3. However, look at the error message:

Test.hs:22:10:
    Could not deduce (mtl-2.1.3.1:Control.Monad.State.Class.MonadState
                        st' (Engine st' m))

      



Explicit package identifiers such as mtl-2.1.3.1

are usually not included in errors. When this is the case, it means that GHC has uploaded two different versions of the package with the same names but different types and classes. In this case, one is probably being used lens

and the other is being used directly by your module.

Cabal sandboxes are one way to avoid this (they provide consistent package versions).

+4


source







All Articles