Also dachte ich mir, ich hätte ein bisschen Spaß beim Analysieren einiger AIS-Daten mit Boomerang, und ich stolpere an der ersten Hürde. Die Kompilierungsfehler sind verwirrend. Ich sehe ähnliche Dinge in Boomerang, bevor ich festhalte, um das Problem zu lösen.Haskell Boomerang Compilation Error
Die Bibliothek ist einfach. Ich sehe einige grundlegende Typen und ihre Parser/Grammatik:
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 ","
ich jetzt wollen den Satz Zählwert unterstützen, die nach dem Nachrichtentyp kommt; Ich füge eine Int
-AIS
:
data AIS = AIS {
msgType :: MessageType, sCount :: Int
} deriving (Eq, Show)
und den Parser/Drucker ändern:
aisP :: StringBoomerang() (AIS :-())
aisP = rAIS . messageTypeP . lit "," . int
aber es funktioniert nicht kompilieren:
• 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
Ouch. Hilfe bitte?
Perfekt. Vielen Dank :) –