[Haskell-cafe] GetOpt

John Meacham john at repetae.net
Thu Apr 27 18:21:23 EDT 2006

I wrote an option parser that infers everything about the options from
the types of what you pull out of it so there is no need to specify
redundant information and you can write very concise code (especially when combined with
the overloaded regex module!)

like for instance

main = do
 (args,(verb,output_name)) <- getOptions ("v|verbose", "o")
 putStrLn $ if verb then "verbose mode" else "not verbose"
 case output_name of
        Nothing -> putStrLn "no output"
        Just fn -> putStrLn $ "output file is: " ++ fn

will just work, infering from the type that '-v' and '-verbose' are
simple flags, while '-o' takes a string argument.

you can even set help messages with the (??) operator

"o" ?? "output file name"

and default values with the (==>) operator.

"o" ==> "out.txt"

it can be gotten here:
and help is at:


John Meacham - ⑆repetae.net⑆john⑈

More information about the Haskell-Cafe mailing list