2
我正在使用Parsec 3.1.2與GHC 7.4.1來嘗試編寫一個有點多毛的數據文件格式的解析器。我有我認爲是一個很平凡的情況,但我得到一個類型錯誤。我試圖遵循Real World Haskell的應用函數示例。Parsec輸入錯誤
import Text.ParserCombinators.Parsec hiding (many, optional, (<|>))
import Text.ParserCombinators.Parsec.Char
import Text.Parsec.String
import Control.Applicative
p_int = many char ' ' *> many1 digit <* many char ' '
現在,原來我得到了以下類型的錯誤:
Couldn't match expected type `[Char]'
with actual type `Text.Parsec.Prim.ParsecT s0 u0 m0 [a0]'
In the return type of a call of `many1'
In the second argument of `(*>)', namely `many1 digit'
In the first argument of `(<*)', namely
`many char ' ' *> many1 digit'
基於Trivial parsec example produces a type error我嘗試添加了NoMonomorphismRestriction
語言編譯,但是這並沒有幫助。
我承認,儘管我有一點Haskell的經驗,但我發現Parsec的學習曲線相當陡峭。它沒有幫助的真實世界哈斯克爾書上的例子是基於秒差距2.
D'哦,我應該抓住這一點。事實上,這確實解決了問題,並將它推向別處。我會爲此提出一個單獨的問題。 –