1

我正在尝试在 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

显然这是代码中唯一有问题的部分 in 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。

所以无论如何,任何有助于了解这一点的帮助将不胜感激,内森

4

0 回答 0