
16 Oct
2010
16 Oct
'10
4:59 p.m.
The avoiding /try/ is a good part of Parsec golf. Because turning natural literals into fractions is easy (%1) it is simple to use the /option/ parser to parse a suffix or return a default. /symbol/ is also a valuable parser, often preferable to /char/ or /string/ as it chomps trailing white space. symbol = P.symbol lexer fraction :: Parser Rational fraction = do num <- integer den <- option 1 (symbol "/" >> natural) return (num % den)