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
哎喲。請幫助?
完美。謝謝 :) –