[Haskell-cafe] Program Command Line Arguments
Donald Bruce Stewart
dons at cse.unsw.edu.au
Sat Mar 10 20:51:16 EST 2007
Dave:
> My apologies if this is a question with a trivial answer.
> Command line args in C are accessed via argc and argv[]
> defined as arguments to main();.
>
> How are command line arguments to a ghc-compiled program
> accessed in Haskell? Or is that even possible?
Simplest: System.Environment:getArgs
import System.Environment
main = do
args <- getArgs
print args
http://haskell.org/ghc/docs/latest/html/libraries/base/System-Environment.html
Complex: System.Console.GetOpt
Example here: http://cgi.cse.unsw.edu.au/~dons/blog/2006/12/18#ph-3
http://haskell.org/ghc/docs/latest/html/libraries/base/System-Console-GetOpt.html
You can find these functions yourself with hoogle:
http://haskell.org/hoogle/
Searching for 'args' returns:
System. getArgs :: IO [String]
Cheers,
Don
P.S. This question is best asked on #haskell possibly (http://haskell.org/haskellwiki/IRC_channel)
More information about the Haskell-Cafe
mailing list