在Quipper中编译GHC程序的错误

时间:2017-11-25 06:05:09

标签: haskell functional-programming ghc quantum-computing

我正在尝试使用Quipper编译程序,Quipper是该站点的官方量子编程语言: http://mathstat.dal.ca/~selinger/quipper/

我无法进行编译,我认为这必须是与GHC或Haskell相关的问题,因为Quipper本身没有明显的错误。

我使用以下命令编译程序:

cd ~/quipper-0.8/quipper/scripts/
sudo ./quipper ~/quipper-0.8/tests/name.hs

我收到的错误如下:

[13 of 21] Compiling Quipper.QData    ( ../../quipper/Quipper/QData.hs, ../../quipper/Quipper/QData.o )

../../quipper/Quipper/QData.hs:965:20:
Could not deduce (QCType Bool Bool s0
                  ~ QCType Int Bool (QCType Bit Bit s))
from the context (QData s)
  bound by the type signature for
             qdata_promote_c :: QData s =>
                                BType s -> CType s -> ErrMsg -> BType s
  at ../../quipper/Quipper/QData.hs:965:20-71
NB: ‘QCType’ is a type function, and may not be injective
The type variable ‘s0’ is ambiguous
Expected type: BType s -> CType s -> ErrMsg -> BType s
  Actual type: BType s0 -> CType s0 -> ErrMsg -> BType s0
In the ambiguity check for the type signature for ‘qdata_promote_c’:
  qdata_promote_c :: forall s.
                     QData s =>
                     BType s -> CType s -> ErrMsg -> BType s
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature for ‘qdata_promote_c’:
  qdata_promote_c :: (QData s) =>
                     BType s -> CType s -> ErrMsg -> BType s

QData.hs中引用的代码行如下所示:

-- | Like 'qdata_promote', except take a piece of classical data.
qdata_promote_c :: (QData s) => BType s -> CType s -> ErrMsg -> BType s
qdata_promote_c b c s = qdata_promote b q s where
q = qdata_map (shapetype_c c) map_qubit c

map_qubit :: Bit -> Qubit
map_qubit = const qubit

显然,它是QData.hs中出现问题的代码的唯一部分,但当我发表评论时,我收到此错误:

[13 of 21] Compiling Quipper.QData    ( ../../quipper/Quipper/QData.hs, ../../quipper/Quipper/QData.o )
[14 of 21] Compiling Quipper.Generic  ( ../../quipper/Quipper/Generic.hs, ../../quipper/Quipper/Generic.o )

../../quipper/Quipper/Generic.hs:257:13:
Not in scope: ‘qdata_promote_c’
Perhaps you meant one of these:
  ‘qdata_promote’ (imported from Quipper.QData),
  ‘qcdata_promote’ (imported from Quipper.QData)

正如你所看到的,这一次它接受了[13 of 21],但在14岁时打破了,因为它取决于我注释掉的功能。当我尝试遵循其建议时,添加AllowAmbiguousTypes:

sudo ./quipper ~/quipper-0.8/tests/name.hs -XAllowAmbiguousTypes

我得到更多错误:

[13 of 21] Compiling Quipper.QData    ( ../../quipper/Quipper/QData.hs, ../../quipper/Quipper/QData.o )

../../quipper/Quipper/QData.hs:966:25:
Could not deduce (QCType
                    Bool Bool (QCType Qubit Qubit (QCType Qubit Qubit s0))
                  ~ QCType Int Bool (QCType Bit Bit s))
from the context (QData s)
  bound by the type signature for
             qdata_promote_c :: QData s =>
                                BType s -> CType s -> ErrMsg -> BType s
  at ../../quipper/Quipper/QData.hs:965:20-71
NB: ‘QCType’ is a type function, and may not be injective
The type variable ‘s0’ is ambiguous
Expected type: BType s
  Actual type: BType (HType Qubit s0)
Relevant bindings include
  q :: HType Qubit s0 (bound at ../../quipper/Quipper/QData.hs:967:3)
  c :: CType s (bound at ../../quipper/Quipper/QData.hs:966:19)
  b :: BType s (bound at ../../quipper/Quipper/QData.hs:966:17)
  qdata_promote_c :: BType s -> CType s -> ErrMsg -> BType s
    (bound at ../../quipper/Quipper/QData.hs:966:1)
In the expression: qdata_promote b q s
In an equation for ‘qdata_promote_c’:
    qdata_promote_c b c s
      = qdata_promote b q s
      where
          q = qdata_map (shapetype_c c) map_qubit c
          map_qubit :: Bit -> Qubit
          map_qubit = const qubit

../../quipper/Quipper/QData.hs:967:30:
Could not deduce (QCType Bit Bit s0 ~ QCType Bit Bit s)
from the context (QData s)
  bound by the type signature for
             qdata_promote_c :: QData s =>
                                BType s -> CType s -> ErrMsg -> BType s
  at ../../quipper/Quipper/QData.hs:965:20-71
NB: ‘QCType’ is a type function, and may not be injective
The type variable ‘s0’ is ambiguous
Expected type: CType s0
  Actual type: CType s
Relevant bindings include
  q :: HType Qubit s0 (bound at ../../quipper/Quipper/QData.hs:967:3)
  c :: CType s (bound at ../../quipper/Quipper/QData.hs:966:19)
  b :: BType s (bound at ../../quipper/Quipper/QData.hs:966:17)
  qdata_promote_c :: BType s -> CType s -> ErrMsg -> BType s
    (bound at ../../quipper/Quipper/QData.hs:966:1)
In the first argument of ‘shapetype_c’, namely ‘c’
In the first argument of ‘qdata_map’, namely ‘(shapetype_c c)’

../../quipper/Quipper/QData.hs:967:43:
Could not deduce (QCType Bit Bit (QCType Qubit Qubit s0)
                  ~ QCType Bit Bit s)
from the context (QData s)
  bound by the type signature for
             qdata_promote_c :: QData s =>
                                BType s -> CType s -> ErrMsg -> BType s
  at ../../quipper/Quipper/QData.hs:965:20-71
NB: ‘QCType’ is a type function, and may not be injective
The type variable ‘s0’ is ambiguous
Expected type: HType Bit s0
  Actual type: CType s
Relevant bindings include
  q :: HType Qubit s0 (bound at ../../quipper/Quipper/QData.hs:967:3)
  c :: CType s (bound at ../../quipper/Quipper/QData.hs:966:19)
  b :: BType s (bound at ../../quipper/Quipper/QData.hs:966:17)
  qdata_promote_c :: BType s -> CType s -> ErrMsg -> BType s
    (bound at ../../quipper/Quipper/QData.hs:966:1)
In the third argument of ‘qdata_map’, namely ‘c’
In the expression: qdata_map (shapetype_c c) map_qubit c

这一切都源于我在QData.hs上面引用的完全相同的一行。请注意,这些错误中没有一个显然与name.hs中我自己的代码有关。

我注意到这个网站没有Quipper的直接帮助(我已经通过电子邮件向负责Quipper的人发送电子邮件但没有回复),但我很确定这是我编译它的方式存在问题,因为这些错误消息不是来自Quipper,而是来自GHC或Haskell。

所以无论如何,任何有助于深入了解这一点的人都会受到赞赏, 森

0 个答案:

没有答案