缺少MonadReader的实例

时间:2016-03-24 10:18:18

标签: haskell typeclass type-constraints type-families

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.1transformers 0.5.2lens 4.14zippers 0.2),base除外4.8只能{{1} } ghc-7.104.9 ghc-8。我真的无法弄清楚为什么它应该用一个编译器而不是另一个编译器编译。我想使代码也适用于ghc-7.10

1 个答案:

答案 0 :(得分:0)

我仍然不知道为什么会出现这个问题。但是,如果用户puregreen#haskell irc频道提供了帮助,我可以通过简单地将view focus替换为(^. focus)来解决此问题。