【问题标题】:Not in scope in Haskell不在 Haskell 范围内
【发布时间】:2015-01-08 06:52:14
【问题描述】:

当我尝试从http://michaeldadams.org/papers/scrap_your_zippers/ScrapYourZippers.hs 编译代码时,我得到:

ScrapYourZipper.hs:249:15: Not in scope: type variable ‘hole’   
ScrapYourZipper.hs:251:27: Not in scope: type variable ‘root’
ScrapYourZipper.hs:252:20: Not in scope: type variable ‘hole’ 
ScrapYourZipper.hs:252:25: Not in scope: type variable ‘root’

发生这种情况的代码部分:

245    data Context hole root where
246    CtxtNull :: Context a a
247    CtxtCons ::
248      forall rights parent. (Data parent) =>
249        Left (hole -> rights)
250        -> Right rights parent
251        -> Context parent root
252        -> Context hole root

有什么想法/指向什么问题?

PS:抱歉帖子命名不好,想不出有意义的东西。

【问题讨论】:

    标签: haskell scope winghci


    【解决方案1】:

    我将该数据声明替换为:

    data Context hole root where
        CtxtNull :: Context a a
        CtxtCons :: (Data parent) => Left (hole -> rights) -> Right rights parent -> Context parent root -> Context hole root
    

    (即删除 forall 子句)并编译。

    【讨论】:

    • 啊,是的,删除forall 更加简单。
    • 你试过编译整个代码吗?我收到一堆错误,例如“无法将预期类型‘hole -> t1’与实际类型‘t’匹配,因为类型变量‘hole’会超出其范围”
    • 将您的完整代码发布到某个地方(例如 lpaste/pastebin),我会看一下。我可以通过上述更改编译 ScrapeYourZipper.hs 文件。
    • 很抱歉,我在编译时只使用了一部分代码。
    【解决方案2】:

    第 248 行应该是

    forall rights parent root hole. (Data parent) =>
    

    在旧版本中,GHC 可能在这里更宽松...

    【讨论】:

    • 但是如果我只使用根或只使用孔,那很好,虽然我仍然得到另一个变量的错误。
    • 很抱歉,我在编译时只使用了一段代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    相关资源
    最近更新 更多