Haskell Boomerang汇编误差



所以我想我会用Boomerang解析一些AIS数据,而我在第一个障碍上绊倒了。汇编错误令人困惑。看到我在试图解决这个问题之前在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

ouch。请帮忙?

boomerangs应该是多态性的。

messageTypeP :: StringBoomerang r (MessageType :- r)
aisP :: StringBoomerang r (AIS :- r)

解释是r是类型的堆栈,而Boomerangs从其中/推出类型。将r设置为()迫使输入堆栈为空,这会损害这些回旋镖的可重复性。

最新更新