or1ko's diary

日々を書きます

単純なParsec利用例2

5文字の入力がある場合、OKと表示し、
そうでない場合に、NGと表示する例

module Main where
import System.IO
import Text.ParserCombinators.Parsec

main = getContents >>= return . ngok . parseSimple >>= print

parseSimple input = parse simple "(unknown)" input

simple = count 5 letter

ngok = either (\_ -> "NG") (\_ -> "OK")
> runghc .\ValueParser.hs
abced
"OK"
> runghc .\ValueParser.hs
abce
"NG"