Haskell 在Quipper中编译GHC程序时出错

Haskell 在Quipper中编译GHC程序时出错,haskell,functional-programming,ghc,quantum-computing,Haskell,Functional Programming,Ghc,Quantum Computing,我正在尝试用Quipper编译一个程序,Quipper是本网站的官方量子编程语言: 我在编译它时遇到了麻烦,我认为这一定是与GHC或Haskell有关的问题,因为Quipper本身没有突出的bug 我使用以下命令编译程序: cd ~/quipper-0.8/quipper/scripts/ sudo ./quipper ~/quipper-0.8/tests/name.hs 我收到的错误如下所示: [13 of 21] Compiling Quipper.QData ( ../../q

我正在尝试用Quipper编译一个程序,Quipper是本网站的官方量子编程语言:

我在编译它时遇到了麻烦,我认为这一定是与GHC或Haskell有关的问题,因为Quipper本身没有突出的bug

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

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
-- | 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 )

../../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
-- | 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/21]
,但在14日中断,因为它依赖于我注释掉的函数。当我尝试按照它的建议添加AllowAmbigUstypes时:

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

所以不管怎样,如果有人能帮我弄清真相,我们将不胜感激,
Nathan

您使用的是什么版本的GHC?Quipper使用了很多高级类型级别的机器,这对于GHC版本来说有点脆弱。我记得我试着给Quipper打补丁,让它在7.10上运行,我的错误与之类似。好吧,7.10 simple不适用于Quipper…我对Quipper一无所知,但错误建议在
q_data\u promotec
中添加
Proxy s
arg可能会有所帮助。或者,您可以使用含糊不清的类型,但这也需要使用TypeApplications在每个使用站点上指定含糊不清的类型。根据整个代码体的外观,其中一个可能更方便您。Alec我的版本显然是7.10.3:
ghc:amd64/xenial 7.10.3-7 Update
。我按照上的说明运行了安装了ghc 8.0.2的
堆栈设置
。但当上述问题持续存在时,当我再次检查GHC版本时,它仍然显示为7.10.3 WTH?!User24这是我第一次在haskell中编程,所以我不完全确定在哪里添加argto@NathanGoedeke不幸的是,如果您不熟悉Haskell的一些更高级的类型级别特性(当然,要熟悉这些特性,您必须熟悉基础知识)你会发现使用这样一个高级类型级特性的库非常困难。你使用的是什么版本的GHC?Quipper使用了很多高级类型级别的机器,这对于GHC版本来说有点脆弱。我记得我试着给Quipper打补丁,让它在7.10上运行,我的错误与之类似。好吧,7.10 simple不适用于Quipper…我对Quipper一无所知,但错误建议在
q_data\u promotec
中添加
Proxy s
arg可能会有所帮助。或者,您可以使用含糊不清的类型,但这也需要使用TypeApplications在每个使用站点上指定含糊不清的类型。根据整个代码体的外观,其中一个可能更方便您。Alec我的版本显然是7.10.3:
ghc:amd64/xenial 7.10.3-7 Update
。我按照上的说明运行了安装了ghc 8.0.2的
堆栈设置
。但当上述问题持续存在时,当我再次检查GHC版本时,它仍然显示为7.10.3 WTH?!User24这是我第一次在haskell中编程,所以我不完全确定在哪里添加argto@NathanGoedeke不幸的是,如果您不熟悉Haskell的一些更高级的类型级别特性(当然,要熟悉这些特性,您必须熟悉基础知识)您会发现使用一个利用了这种高级类型级别特性的库是非常困难的。