为什么会失败?
data Value = Num Integer
| Str String
let numberOrString = (liftM Num (try int) <|> liftM Str (many1 (noneOf " "))
parse (numberOrString >> space) "" "123-4 "
>> space
是必需的。否则解析器将在之后停止123
预期结果:
parse numberOrString "" "1234"
-> Num 1234
parse numberOrString "" "12-34"
-> Str "12-34"
结果:
parse numberOrString "" "1234-34 "
-> Left (line 1, column 5):
unexpected "-"
expecting digit or space