从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除外,后者只能是ghc-7.10的4.8,4.9只能用于ghc-8。我真的不明白为什么它应该用一个编译器而不是另一个编译器编译。我也想让代码为ghc-7.10工作。
发布于 2016-05-16 13:53:26
我仍然不知道为何会出现这个问题。但是,在用户puregreen over的帮助下,在#haskell irc通道上,我能够通过简单地用(^. focus)替换view focus来克服这个问题。
https://stackoverflow.com/questions/36197795
复制相似问题