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)
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to