[Haskell] main::[String]->IO() ?

Mikael Brockman phubuh at phubuh.org
Mon Mar 22 22:31:49 EST 2004


Steffen Mazanek <s_mazanek at gmx.de> writes:

> Hello everybody,
>
> each time I write an application that makes use of command line arguments
> I have to copy&paste the code for dealing with these args to my program 
> from a reference implementation, because it is so hard to remember.
> What do you think about changing the default type of main or providing
> an alternative, e.g., main_args, just like in C or Java?
>
> I think this would simplify everyday-programming a lot. Or are there
> any severe theoretical (semantical) problems (main is running in the IO 
> monad either way)? 
>
> Ciao,
> Steffen

  main_args :: [String] -> IO ()
  main_args args = do foo args
                      bar args

versus
                    
  main :: IO ()
  main = do args <- getArgs
            foo args
            bar args

Frankly, I don't think there's a compelling reason to change main's
type or introduce a new entry point.  Not that I don't think that
accepting a [String] is slightly more elegant.

Have you considered one of the more sophisticated high-level argument
libraries?

Hugs & kisses,
Mikael Brockman



More information about the Haskell mailing list