【问题标题】:Issues compiling thrift tutorial with GHC 7.6.3使用 GHC 7.6.3 编译 thrift 教程的问题
【发布时间】:2013-06-21 20:16:57
【问题描述】:

我尝试使用 ghc 7.6.3 将文件 HaskellServer.hs 从 thrift-0.9.0/tutorial/hs 编译为 没用。

在我调用的命令行上

thrift --gen hs tutorial.thrift

thrift --gen hs shared.thrift

没有任何错误。

之后,我尝试编译

ghc HaskellServer.hs

但我得到以下错误输出:

[1 of 7] Compiling Shared_Types     ( Shared_Types.hs, Shared_Types.o ) [flags changed]
[2 of 7] Compiling SharedService_Iface ( SharedService_Iface.hs, SharedService_Iface.o ) [flags
changed]
[3 of 7] Compiling SharedService    ( SharedService.hs, SharedService.o ) [flags changed]
[4 of 7] Compiling Tutorial_Types   ( Tutorial_Types.hs, Tutorial_Types.o ) [flags changed]
[5 of 7] Compiling Calculator_Iface ( Calculator_Iface.hs, Calculator_Iface.o ) [flags changed]
[6 of 7] Compiling Calculator       ( Calculator.hs, Calculator.o ) [flags changed]
[7 of 7] Compiling Main             ( HaskellServer.hs, HaskellServer.o )

HaskellServer.hs:48:33:
    Couldn't match type `GHC.Int.Int32' with `Int'
    Expected type: Maybe Int
      Actual type: Maybe GHC.Int.Int32
    In the first argument of `fromJust', namely `k'
    In the second argument of `(!)', namely `(fromJust k)'
    In the second argument of `($)', namely `(myLog ! (fromJust k))'

HaskellServer.hs:73:60:
    Couldn't match type `Int' with `GHC.Int.Int32'
    Expected type: Maybe GHC.Int.Int32
      Actual type: Maybe Int
    In the `f_InvalidOperation_what' field of a record
    In the second argument of `($)', namely
      `InvalidOperation
         {f_InvalidOperation_what = Just $ fromEnum $ op work,
          f_InvalidOperation_why = Just "Cannot divide by 0"}'
    In the expression:
      throw
      $ InvalidOperation
          {f_InvalidOperation_what = Just $ fromEnum $ op work,
           f_InvalidOperation_why = Just "Cannot divide by 0"}

HaskellServer.hs:74:64:
    Couldn't match expected type `Data.Text.Lazy.Internal.Text'
                with actual type `[Char]'
    In the first argument of `Just', namely `"Cannot divide by 0"'
    In the `f_InvalidOperation_why' field of a record
    In the second argument of `($)', namely
      `InvalidOperation
         {f_InvalidOperation_what = Just $ fromEnum $ op work,
          f_InvalidOperation_why = Just "Cannot divide by 0"}'

HaskellServer.hs:79:53:
    Couldn't match type `[Char]' with `Data.Text.Lazy.Internal.Text'
    Expected type: Data.Text.Lazy.Internal.Text
      Actual type: String
    In the return type of a call of `show'
    In the first argument of `Just', namely `(show val)'
    In the second argument of `SharedStruct', namely
      `(Just (show val))'

HaskellServer.hs:80:52:
    Couldn't match expected type `Int' with actual type `GHC.Int.Int32'
    In the first argument of `M.insert', namely `logid'
    In the second argument of `(.)', namely `(M.insert logid logEntry)'
    In the second argument of `($)', namely
      `return . (M.insert logid logEntry)'

显然,类型有问题,但我不能说这是否是我的具体问题 GHC 版本或 Thrift 本身。

这是第一条错误消息的代码 (HaskellServer.hs:48:33):

instance SharedService_Iface CalculatorHandler where
  getStruct self k = do
    myLog <- readMVar (mathLog self)
    return $ (myLog ! (fromJust k))

有人可以指出正确的方向吗?


更新

生成的 thrift 文件列出了使用的编译标志:

{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
{-# OPTIONS_GHC -fno-warn-missing-fields #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

【问题讨论】:

  • GHC 重新编译所有模块看起来很可疑,因为[flags changed]。知道thrift 传递了哪些标志现在丢失了会很有趣。
  • @DanielFischer 我已经用我找到的编译标志更新了我的问题。你怎么看?
  • 嗯,-fno-warn-xyz 不应被视为需要重新编译的标志更改。 thrift --gen hs shared.thrift 是否可以在详细模式下运行,从而输出 GHC 调用?
  • 好吧,我试过thrift -debug -v --gen hs shared.thrift,但输出有点没用。它只是打印解析输出,最后在返回提示之前说Generating "hs"。任何地方都没有提到 ghc。
  • 呸。我不会为了调试这个问题而安装 thrift(不管是什么),所以恐怕我无法帮助你,抱歉。

标签: haskell types ghc thrift


【解决方案1】:

如果不查看更多代码,很难知道您实际使用的是什么类型,但我在这里有一种预感,即 thrift 会生成预期 GHC.Int.Int32 的东西,而您的代码会预期 Int

【讨论】:

  • 可能就是这样。所有代码均来自 thrift 包附带的官方教程。也许 Haskell 教程已经过时了?
猜你喜欢
  • 2012-11-24
  • 1970-01-01
  • 1970-01-01
  • 2018-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-30
  • 1970-01-01
相关资源
最近更新 更多