简体   繁体   English

使用GHC 7.6.3编译节俭教程的问题

[英]Issues compiling thrift tutorial with GHC 7.6.3

I tried compiling the file HaskellServer.hs from thrift-0.9.0/tutorial/hs with ghc 7.6.3 to no avail. 我尝试使用ghc 7.6.3从thrift-0.9.0 / tutorial / hs编译文件HaskellServer.hs无效。

On the commandline I called 在命令行上,我打电话给

thrift --gen hs tutorial.thrift 节俭--gen hs tutorial.thrift

thrift --gen hs shared.thrift thrift --gen hs shared.thrift

which worked without any errors. 没有任何错误的工作。

After that, I tried to compile with 之后,我尝试用

ghc HaskellServer.hs ghc HaskellServer.hs

but I get the following error output: 但我得到以下错误输出:

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

Obviously, something's wrong with the types but I can't say if it's a problem with my specific GHC version or with thrift itself. 显然,类型有问题,但是我不能说这是我的特定GHC版本还是节俭本身的问题。

Here is the code for the first error message (HaskellServer.hs:48:33): 这是第一个错误消息的代码(HaskellServer.hs:48:33):

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

Can somebody point me in the right direction? 有人可以指出我正确的方向吗?


Update 更新

The generated thrift files list the compile flags used: 生成的节俭文件列出了使用的编译标志:

{-# 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.Int.Int32东西,而您的代码GHC.Int.Int32期望Int

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM