質問

私は、fparsecを使用してコメントをホワイトスペースとして扱うパーサーを実装しています。些細なパーサー変換が必要なようですが、それを実装する方法はまだわかりません。

これが私がタイプチェックしようとしているコードです -

let whitespaceTextChars = " \t\r\n"

/// Read whitespace characters.
let whitespaceText = many (anyOf whitespaceTextChars)

/// Read a line comment.
let lineComment = pchar lineCommentChar >>. restOfLine true

/// Skip any white space characters.
let skipWhitespace = skipMany (lineComment <|> whitespaceText)

/// Skip at least one white space character.
let skipWhitespace1 = skipMany1 (lineComment <|> whitespaceText)

エラーは両方の2番目の引数にあります <|> オペレーター(オーバー whitespaceText)。エラーは -

Error   1   Type mismatch. Expecting a     Parser<string,'a>     but given a     Parser<char list,'a>     The type 'string' does not match the type 'char list'
Error   2   Type mismatch. Expecting a     Parser<string,'a>     but given a     Parser<char list,'a>     The type 'string' does not match the type 'char list'

変換する必要があるようです Parser<char list, 'a>Parser<string, 'a>. 。または、私はそれらをスキップしているだけなので、私はそれらを両方に変換することができます Parser<unit, 'a>. 。しかし、私はそのコードを書く方法がわかりません。それはいくつかの単純なラムダの表現ですか?

乾杯!

役に立ちましたか?

解決

let whitespaceText = manyChars (anyOf whitespaceTextChars)

また

let whitespaceText = many (anyOf whitespaceTextChars) |>> fun cs -> System.String (Array.ofList cs)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top