Parsec.Combinator:count

module Main where

import Text.ParserCombinators.Parsec

test1 :: Parser String
test1 =  count 3 letter

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> run test1 ""
Loading package parsec ... linking ... done.
parse error at (line 1, column 1):
unexpected end of input
expecting letter
*Main> run test1 "aa"
parse error at (line 1, column 3):
unexpected end of input
expecting letter
*Main> run test1 "aaa"
"aaa"
*Main> run test1 "aaaa"
"aaa"