首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缺少MonadReader实例

缺少MonadReader实例
EN

Stack Overflow用户
提问于 2016-03-24 10:18:18
回答 1查看 154关注 0票数 1

github获得的代码

代码语言:javascript
复制
{-# 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编译错误

代码语言:javascript
复制
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除外,后者只能是ghc-7.104.84.9只能用于ghc-8。我真的不明白为什么它应该用一个编译器而不是另一个编译器编译。我也想让代码为ghc-7.10工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-16 13:53:26

我仍然不知道为何会出现这个问题。但是,在用户puregreen over的帮助下,在#haskell irc通道上,我能够通过简单地用(^. focus)替换view focus来克服这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36197795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档