Cabal构建产生错误 - 代码看起来很好吗?

时间:2018-03-06 23:30:07

标签: haskell cabal happy alex

在我的开发过程中,我一直在手动运行alex / happy来生成我的解析器文件,然后运行ghci来测试代码。这工作正常,并将我加载到GHCI,但每当我运行cabal repl时,程序在我的Parser.hs文件中引发错误。

错误是类型错误:Couldn't match type '[a]' with 'Expression'但是,只要我使用ghci main手动测试此代码,代码运行正常吗?

我不确定我是否还没有完全理解cabal是如何工作的,但我注意到从快乐和来自cabal生成的haskell解析器是完全不同的。

我已经为下面的cabal构建命令附加了错误消息的开头。

修改

正如Alec所指出的那样,无论何时运行cabal构建它都会对-agc标志感到满意,我对此并不了解,因此我需要调整代码。

解决方案是使用-agc标志构建Happy解析器,并确保它以这种方式编译。这可能会导致解析器中出现一些新错误,因为生成的解析器略有不同,但根据我的研究,如果没有前面提到的标记,cabal repl无法快乐地运行。

  PS D:\Documents\GitHub\solidiscan> cabal build
  Preprocessing executable 'solidiscan' for solidiscan-0.1.0.0..
  Building executable 'solidiscan' for solidiscan-0.1.0.0..
  [3 of 6] Compiling Solidiscan.Parser ( dist\build\solidiscan\solidiscan-tmp\Solidiscan\Parser.hs, dist\build\solidiscan\solidiscan-tmp\Solidiscan\Parse
  r.o )

  dist\build\solidiscan\solidiscan-tmp\Solidiscan\Parser.hs:2429:42: error:
      * Couldn't match type `[a]' with `Expression'
        Expected type: HappyAbsSyn
                        [SourceUnit]
                        SourceUnit
                        [Char]
                        [Char]
                        Token
                        InheritanceSpec
                        InheritanceSpecifier
                        InheritanceSpecifier
                        [Expression]
                        Expression
                        [[Expression]]
                        [Expression]
                        [EnumValue]
                        EnumValue
                        [[EParameters]]
                        [EParameters]
                        EParameters
                        Token
                        [[Parameter]]
                        [Parameter]
                        Parameter
                        ReturnParam
                        [Expression]
                        Token
                        Token
                        PublicKeyword
                        [a]
                        [a]
                        [Expression]
                        Expression
                        TypeName
                        [Expression]
                        Expression
                        Expression
                        Expression
                        Expression
                        ElseState
                        Int
                        TypeName
                        ElemType
                        [Expression]
                        [ContractConts]
                        [EParameters]
                        [Expression]
                        [FuncMods]
                        [[Expression]]
                        [EnumValue]
                        [InheritanceSpecifier]
                        [Parameter]
                        [Expression]
                        [Token]
                        [PublicKeyword]
                        [ElseState]
                        [[[EParameters]]]
                        [[EParameters]]
                        [Expression]
                        [[Expression]]
                        [InheritanceSpec]
                        [Expression]
                        [[[Parameter]]]
                        [[Parameter]]
                        [ReturnParam]
                        [StorageLocation]
                        [Expression]
                        [ContractConts]
                        [EParameters]
                        [Expression]
                        [FuncMods]
                        [[Expression]]
                        [EnumValue]
                        [InheritanceSpecifier]
                        [Parameter]
                        [Expression]
                      -> HappyAbsSyn
                            [SourceUnit]
                            SourceUnit
                            [Char]
                            [Char]
                            Token
                            InheritanceSpec
                            InheritanceSpecifier
                            InheritanceSpecifier
                            [Expression]
                            Expression
                            [[Expression]]
                            [Expression]
                            [EnumValue]
                            EnumValue
                            [[EParameters]]
                            [EParameters]
                            EParameters
                            Token
                            [[Parameter]]
                            [Parameter]
                            Parameter
                            ReturnParam
                            [Expression]
                            Token
                            TypeName
                            PublicKeyword
                            [a]
                            Expression
                            [Expression]
                            Expression
                            TypeName
                            [Expression]
                            Expression
                            Expression
                            Expression
                            Expression
                            ElseState
                            Int
                            TypeName
                            ElemType
                            [Expression]
                            [ContractConts]
                            [EParameters]
                            [Expression]
                            [FuncMods]
                            [[Expression]]
                            [EnumValue]
                            [InheritanceSpecifier]
                            [Parameter]
                            [Expression]
                            [Token]
                            [PublicKeyword]
                            [ElseState]
                            [[[EParameters]]]
                            [[EParameters]]
                            [Expression]
                            [[Expression]]
                            [InheritanceSpec]
                            [Expression]
                            [[[Parameter]]]
                            [[Parameter]]
                            [ReturnParam]
                            [StorageLocation]
                            [Expression]
                            [ContractConts]
                            [EParameters]
                            [Expression]
                            [FuncMods]
                            [[Expression]]
                            [EnumValue]
                            [InheritanceSpecifier]
                            [Parameter]
                            [Expression]
          Actual type: HappyAbsSyn
                        [SourceUnit]
                        SourceUnit
                        [Char]
                        [Char]
                        Token
                        InheritanceSpec
                        InheritanceSpecifier
                        InheritanceSpecifier
                        [Expression]
                        Expression
                        [[Expression]]
                        [Expression]
                        [EnumValue]
                        EnumValue
                        [[EParameters]]
                        [EParameters]
                        EParameters
                        Token
                        [[Parameter]]
                        [Parameter]
                        Parameter
                        ReturnParam
                        [Expression]
                        Token
                        Token
                        PublicKeyword
                        [a]
                        [a]
                        [Expression]
                        Expression
                        TypeName
                        [Expression]
                        Expression
                        Expression
                        Expression
                        Expression
                        ElseState
                        Int
                        TypeName
                        ElemType
                        [Expression]
                        [ContractConts]
                        [EParameters]
                        [Expression]
                        [FuncMods]
                        [[Expression]]
                        [EnumValue]
                        [InheritanceSpecifier]
                        [Parameter]
                        [Expression]
                        [Token]
                        [PublicKeyword]
                        [ElseState]
                        [[[EParameters]]]
                        [[EParameters]]
                        [Expression]
                        [[Expression]]
                        [InheritanceSpec]
                        [Expression]
                        [[[Parameter]]]
                        [[Parameter]]
                        [ReturnParam]
                        [StorageLocation]
                        [Expression]
                        [ContractConts]
                        [EParameters]
                        [Expression]
                        [FuncMods]
                        [[Expression]]
                        [EnumValue]
                        [InheritanceSpecifier]
                        [Parameter]
                        [Expression]
                      -> HappyAbsSyn
                            [SourceUnit]
                            SourceUnit
                            [Char]
                            [Char]
                            Token
                            InheritanceSpec
                            InheritanceSpecifier
                            InheritanceSpecifier
                            [Expression]
                            Expression
                            [[Expression]]
                            [Expression]
                            [EnumValue]
                            EnumValue
                            [[EParameters]]
                            [EParameters]
                            EParameters
                            Token
                            [[Parameter]]
                            [Parameter]
                            Parameter
                            ReturnParam
                            [Expression]
                            Token
                            TypeName
                            PublicKeyword
                            [a]
                            Expression
                            [Expression]
                            Expression
                            TypeName
                            [Expression]
                            Expression
                            Expression
                            Expression
                            Expression
                            ElseState
                            Int
                            TypeName
                            ElemType
                            [Expression]
                            [ContractConts]
                            [EParameters]
                            [Expression]
                            [FuncMods]
                            [[Expression]]
                            [EnumValue]
                            [InheritanceSpecifier]
                            [Parameter]
                            [Expression]
                            [Token]
                            [PublicKeyword]
                            [ElseState]
                            [[[EParameters]]]
                            [[EParameters]]
                            [Expression]
                            [[Expression]]
                            [InheritanceSpec]
                            [[a]]
                            [[[Parameter]]]
                            [[Parameter]]
                            [ReturnParam]
                            [StorageLocation]
                            [Expression]
                            [ContractConts]
                            [EParameters]
                            [Expression]
                            [FuncMods]
                            [[Expression]]
                            [EnumValue]
                            [InheritanceSpecifier]
                            [Parameter]
                            [Expression]
      * In the second argument of `happySpecReduce_1', namely
          `happyReduction_161'
        In the expression: happySpecReduce_1 81# happyReduction_161
        In an equation for `happyReduce_161':
            happyReduce_161 = happySpecReduce_1 81# happyReduction_161
      * Relevant bindings include
          happyReduce_161 :: Happy_GHC_Exts.Int#
                            -> Token
                            -> Happy_GHC_Exts.Int#
                            -> Happy_IntList
                            -> HappyStk
                                  (HappyAbsSyn
                                    [SourceUnit]
                                    SourceUnit
                                    [Char]
                                    [Char]
                                    Token
                                    InheritanceSpec
                                    InheritanceSpecifier
                                    InheritanceSpecifier
                                    [Expression]
                                    Expression
                                    [[Expression]]
                                    [Expression]
                                    [EnumValue]
                                    EnumValue
                                    [[EParameters]]
                                    [EParameters]
                                    EParameters
                                    Token
                                    [[Parameter]]
                                    [Parameter]
                                    Parameter
                                    ReturnParam
                                    [Expression]
                                    Token
                                    TypeName
                                    PublicKeyword
                                    [a]
                                    Expression
                                    [Expression]
                                    Expression
                                    TypeName
                                    [Expression]
                                    Expression
                                    Expression
                                    Expression
                                    Expression
                                    ElseState
                                    Int
                                    TypeName
                                    ElemType
                                    [Expression]
                                    [ContractConts]
                                    [EParameters]
                                    [Expression]
                                    [FuncMods]
                                    [[Expression]]
                                    [EnumValue]
                                    [InheritanceSpecifier]
                                    [Parameter]
                                    [Expression]
                                    [Token]
                                    [PublicKeyword]
                                    [ElseState]
                                    [[[EParameters]]]
                                    [[EParameters]]
                                    [Expression]
                                    [[Expression]]
                                    [InheritanceSpec]
                                    [Expression]
                                    [[[Parameter]]]
                                    [[Parameter]]
                                    [ReturnParam]
                                    [StorageLocation]
                                    [Expression]
                                    [ContractConts]
                                    [EParameters]
                                    [Expression]
                                    [FuncMods]
                                    [[Expression]]
                                    [EnumValue]
                                    [InheritanceSpecifier]
                                    [Parameter]
                                    [Expression])
                            -> [Token]
                            -> HappyIdentity
                                  (HappyAbsSyn
                                    [SourceUnit]
                                    SourceUnit
                                    [Char]
                                    [Char]
                                    Token
                                    InheritanceSpec
                                    InheritanceSpecifier
                                    InheritanceSpecifier
                                    [Expression]
                                    Expression
                                    [[Expression]]
                                    [Expression]
                                    [EnumValue]
                                    EnumValue
                                    [[EParameters]]
                                    [EParameters]
                                    EParameters
                                    Token
                                    [[Parameter]]
                                    [Parameter]
                                    Parameter
                                    ReturnParam
                                    [Expression]
                                    Token
                                    TypeName
                                    PublicKeyword
                                    [a]
                                    Expression
                                    [Expression]
                                    Expression
                                    TypeName
                                    [Expression]
                                    Expression
                                    Expression
                                    Expression
                                    Expression
                                    ElseState
                                    Int
                                    TypeName
                                    ElemType
                                    [Expression]
                                    [ContractConts]
                                    [EParameters]
                                    [Expression]
                                    [FuncMods]
                                    [[Expression]]
                                    [EnumValue]
                                    [InheritanceSpecifier]
                                    [Parameter]
                                    [Expression]
                                    [Token]
                                    [PublicKeyword]
                                    [ElseState]
                                    [[[EParameters]]]
                                    [[EParameters]]
                                    [Expression]
                                    [[Expression]]
                                    [InheritanceSpec]
                                    [Expression]
                                    [[[Parameter]]]
                                    [[Parameter]]
                                    [ReturnParam]
                                    [StorageLocation]
                                    [Expression]
                                    [ContractConts]
                                    [EParameters]
                                    [Expression]
                                    [FuncMods]
                                    [[Expression]]
                                    [EnumValue]
                                    [InheritanceSpecifier]
                                    [Parameter]
                                    [Expression])
            (bound at dist\build\solidiscan\solidiscan-tmp\Solidiscan\Parser.hs:2429:1)
      |
  2429 | happyReduce_161 = happySpecReduce_1  81# happyReduction_161
      |                                          ^^^^^^^^^^^^^^^^^^

0 个答案:

没有答案