缺少 MonadReader 实例
Missing instance of MonadReader
可从github获得的代码:
{-# LANGUAGE TypeFamilies
, TypeOperators #-}
module Test where
import Control.Monad.Reader
import Control.Lens
import Control.Zipper
class Monad f => Family f where
type Set f
-- This does not work
f :: Family f => (Top :>> [Set f] :>> Set f) -> f (Set f)
f = return . view focus
-- This here works
g :: Top :>> [Int] :>> Int -> Int
g = view focus
使用 ghc-8
编译正常,但使用 ghc-7.10
编译失败并出现错误
Test.hs:16:14:
Could not deduce (MonadReader
(Zipper (Top :>> [Set f]) Int (Set f))
((->) ((Top :>> [Set f]) :>> Set f)))
arising from a use of `view'
from the context (Family f)
bound by the type signature for
f :: Family f => (Top :>> [Set f]) :>> Set f -> f (Set f)
at Test.hs:15:6-57
In the second argument of `(.)', namely `view focus'
In the expression: return . view focus
In an equation for `f': f = return . view focus
在这两种情况下使用完全相同的依赖关系(mtl 2.2.1
、transformers 0.5.2
、lens 4.14
、zippers 0.2
)除了 base
只能是 4.8
ghc-7.10
,4.9
ghc-8
。我真的不明白为什么它应该用一个编译器而不是另一个编译器编译。我想让代码也适用于 ghc-7.10
。
我还不知道为什么会出现这个问题。但是在 #haskell
irc 频道上的用户 puregreen
的帮助下,我能够通过简单地将 view focus
替换为 (^. focus)
.[=14 来解决此设置中的这个问题=]
可从github获得的代码:
{-# LANGUAGE TypeFamilies
, TypeOperators #-}
module Test where
import Control.Monad.Reader
import Control.Lens
import Control.Zipper
class Monad f => Family f where
type Set f
-- This does not work
f :: Family f => (Top :>> [Set f] :>> Set f) -> f (Set f)
f = return . view focus
-- This here works
g :: Top :>> [Int] :>> Int -> Int
g = view focus
使用 ghc-8
编译正常,但使用 ghc-7.10
编译失败并出现错误
Test.hs:16:14:
Could not deduce (MonadReader
(Zipper (Top :>> [Set f]) Int (Set f))
((->) ((Top :>> [Set f]) :>> Set f)))
arising from a use of `view'
from the context (Family f)
bound by the type signature for
f :: Family f => (Top :>> [Set f]) :>> Set f -> f (Set f)
at Test.hs:15:6-57
In the second argument of `(.)', namely `view focus'
In the expression: return . view focus
In an equation for `f': f = return . view focus
在这两种情况下使用完全相同的依赖关系(mtl 2.2.1
、transformers 0.5.2
、lens 4.14
、zippers 0.2
)除了 base
只能是 4.8
ghc-7.10
,4.9
ghc-8
。我真的不明白为什么它应该用一个编译器而不是另一个编译器编译。我想让代码也适用于 ghc-7.10
。
我还不知道为什么会出现这个问题。但是在 #haskell
irc 频道上的用户 puregreen
的帮助下,我能够通过简单地将 view focus
替换为 (^. focus)
.[=14 来解决此设置中的这个问题=]