编译/修复monadiccp类型错误

时间:2011-10-05 01:33:02

标签: generics haskell types typeerror

如果有人可以通过编译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

任何关于这种情况的灯光都会受到最多的赞赏(包括解决问题)。我不久前给开发人员发了一封电子邮件,但他没有回来。

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

我可以稍微弄清楚一些类型定义来编译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进行了线程化。我有理由相信修改后的代码与原文的意图相同。

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