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
只能{{1} } ghc-7.10
和4.9
ghc-8
。我真的无法弄清楚为什么它应该用一个编译器而不是另一个编译器编译。我想使代码也适用于ghc-7.10
。
答案 0 :(得分:0)
我仍然不知道为什么会出现这个问题。但是,如果用户puregreen
对#haskell
irc频道提供了帮助,我可以通过简单地将view focus
替换为(^. focus)
来解决此问题。