0
所以我觉得我会用Boomerang解析一些AIS数据有一些乐趣,而且我在第一个障碍上磕磕绊绊。编译错误令人困惑。看到我在Boomerang解析类似的东西之前,我试图解决这个问题。Haskell Boomerang编译错误
该库很简单。我定义一些基本类型和它们的解析器/语法:
import Control.Category (id, (.))
import Control.Monad (forever)
import Prelude hiding (id, (.))
import System.IO (hFlush, stdout)
import Text.Boomerang
import Text.Boomerang.String
import Text.Boomerang.TH
data MessageType = AIVDM | AIVDO deriving (Enum, Eq, Show)
data AIS = AIS {
msgType :: MessageType
} deriving (Eq, Show)
$(makeBoomerangs ''MessageType)
$(makeBoomerangs ''AIS)
messageTypeP :: StringBoomerang() (MessageType :-())
messageTypeP = rAIVDM . "!AIVDM" <> rAIVDO . "!AIVDO"
aisP :: StringBoomerang() (AIS :-())
aisP = rAIS . messageTypeP . lit ","
我现在希望支持的句子计数值,其自带的消息类型后;我添加Int
到AIS
:
data AIS = AIS {
msgType :: MessageType, sCount :: Int
} deriving (Eq, Show)
和更改解析器/打印机:
aisP :: StringBoomerang() (AIS :-())
aisP = rAIS . messageTypeP . lit "," . int
,但它无法编译:
• Couldn't match type ‘()’ with ‘Int :-()’
Expected type: Boomerang
StringError String() (MessageType :- (Int :-()))
Actual type: Boomerang StringError String() (MessageType :-())
• In the second argument of ‘(.)’, namely
‘messageTypeP . lit "," . int’
In the expression: rAIS . messageTypeP . lit "," . int
In an equation for ‘aisP’:
aisP = rAIS . messageTypeP . lit "," . int
哎哟。请帮助?
完美。谢谢 :) –