[Haskell-beginners] how to access command line arguments

prad prad at towardsfreedom.com
Sat Aug 14 23:39:00 EDT 2010

here's one way:

import System (getArgs)

args <- getArgs

first = head args
last  = last args
and so on.

i can also do this

(first:last:z) <- getArgs

and avoid using head and tail. in fact, this seems nicer because i can
pattern match for a specific series of inputs. however, if the inputs
aren't there (eg say program arg1 only instead of program arg1 arg2),
then the runtime pattern match failure error: 

user error (Pattern match failure in do expression at Tests.hs:14:4-14)

is understandably generated. this of course doesn't happen if i just
use args because there is no pattern matching.

is the former the better way to do it then? or are there other

In friendship,

                                      ... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's

More information about the Beginners mailing list