【问题标题】:compiling / repairing monadiccp type errors编译/修复 monadiccp 类型错误
【发布时间】:2011-12-01 03:13:17
【问题描述】:

如果有人可以通过编译 monadiccp 帮助我研究这个问题,我将不胜感激。有一个我无法理解的打字问题。

重现步骤

  • 安装了最新版本的 ghc;我有 7.0.3
  • cabal install Monatron
  • cabal unpack monadiccp
  • ghci Control/CP/ComposableTransformers.hs

我收到此错误,

Control/CP/ComposableTransformers.hs:246:31:
    Couldn't match expected type `Tree solver0 a1 -> Tree solver0 a1'
                with actual type `forall a2. Tree solver a2 -> Tree solver a2'
    Expected type: Tree solver0 a1 -> Tree solver0 a1
      Actual type: Bound solver
    In the second argument of `BBP', namely `bound''
    In the second argument of `($)', namely `BBP (v + 1) bound''
Failed, modules loaded: Control.CP.Transformers, Control.CP.SearchTree, Control.CP.Solver, Control.CP.Queue, Control.CP.Debug, Control.CP.PriorityQueue, Control.Mixin.Mixin.

这是一个奇怪的观察。如果有人更改有问题的行,

   continue $ BBP (v + 1) bound' 

具有错误中给定类型的特征,

   continue $ BBP (v + 1) (undefined :: Tree solver0 a1 -> Tree solver0 a1)

那么它可以工作,但是如果引入一个虚拟变量,

   let x = (undefined :: Tree solver0 a1 -> Tree solver0 a1)
   continue $ BBP (v + 1) x

类型错误变得更加难以理解(我可能需要正式学习打字),

Control/CP/ComposableTransformers.hs:247:19:
    Couldn't match type `a10' with `a1'
      because type variable `a1' would escape its scope
    This (rigid, skolem) type variable is bound by
      a type expected by the context: Tree solver a1 -> Tree solver a1
    The following variables have types that mention a10
      x :: Tree solver a10 -> Tree solver a10
        (bound at Control/CP/ComposableTransformers.hs:246:12)
    In the second argument of `BBP', namely `x'
    In the second argument of `($)', namely `BBP (v + 1) x'
    In the expression: continue $ BBP (v + 1) x

我们将不胜感激任何对这种情况的了解(包括解决问题)。不久前我向开发者发送了一封电子邮件,但他没有回复。

【问题讨论】:

    标签: generics haskell types typeerror


    【解决方案1】:

    我不是 100% 确定发生了什么,但只需手动重写 do-block 就可以为我编译:

      returnCT (CBBST newBound) (BBP v bound) continue exit =
        newBound >>= continue . BBP (v + 1)
    

    【讨论】:

    • 太好了,非常感谢!看起来还有更多错误......这是一个非常奇怪的问题。
    【解决方案2】:

    我可以通过稍微丑化一些类型定义来编译ComposableTransformers.hs,如:

    newtype CBranchBoundST solver a = CBBST (NewBound solver a)
    data    BBEvalState solver a  = BBP Int (Bound solver a)
    
    type Bound    solver a  = Tree solver a -> Tree solver a
    type NewBound solver a  = solver (Bound solver a)
    
    instance (Solver solver) => CTransformer (CBranchBoundST solver a)
    where
      type CEvalState (CBranchBoundST solver a) = BBEvalState solver a
    

    基本上,我只是通过这些定义线程化了一个类型变量a。我有理由确定修改后的代码与原始代码的意图相同。

    不幸的是,正如最初的提问者所说,还出现了许多其他编译错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多