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!

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.