Parsec.Combinator:choice
module Main where import Text.ParserCombinators.Parsec run :: Show a => Parser a -> String -> IO () run p input = case (parse p "" input) of Left err -> do{ putStr "parse error at " ; print err } Right x -> print x
で、
*Main> :l 20081004_parsec00.hs Compiling Main ( 20081004_parsec00.hs, interpreted ) Ok, modules loaded: Main. *Main> run (choice [digit, space]) "0" '0' *Main> run (choice [digit, space]) "a" parse error at (line 1, column 1): unexpected "a" expecting digit or space *Main> run (choice [digit, space]) " " ' '