Hello, I have an issue using Haskell's Command-Line args functionality. I'm writing a Typechecker for my parser and I need to be able to tell my program via command-line arguments that I can have at most x errors reported where x is:

./typechecker --number-of-errors=x test.cl

This is the run-statement I use after I have compiled my Haskell program using:
make typechecker

I handle this in Main.hs, you can find the relevant code here:

main :: IO ()
main = do
  filenames <- getArgs  -- get the command line arguments
  when (null filenames) (fail "No file name")

  mapM_ (\f -> processFile f `catch` (const (return ()))) filenames

I am confused on how to implement capturing the "--" flag and on top of this, how to capture whatever value x will be. I'm not asking you to complete this for me, I'm just looking for resources to use to help me out. I can't seem to locate the proper modules to include that provide functions for doing this. Any guidance is appreciated!

5 Years
Discussion Span
Last Post by sepp2k

The proper functions are the basic string handling functions. It's called programming. There might be some command line parsing library but it is so trivial to support this feature yourself.

Edited by Rashakil Fol: n/a


The System.Console.GetOpt module (which is part of base and thus doesn't add any dependencies to your project) is the proper way to handle command line arguments.

Yes, it's easy enough to write your own code for handling command line options, but there's no need to. There's no point in reinventing the wheel when it's not necessary.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.