Re: [Haskell] Re: Why is getArgs in the IO monad?

Keean Schupke
Surely both requirements can be satisfied if the programs arguments are made parameters of main:
main :: [String] -> IO ()
From info '(libc)Error Messages', about program_invocation_name and program_invocation_short_name:
*Portability Note:* These two variables are GNU extensions. If you want your program to work with non-GNU libraries, you must save the value of `argv[0]' in `main', and then strip off the directory names yourself. We added these extensions to make it possible to write self-contained error-reporting subroutines that require no explicit cooperation from `main'. This suggests that making global parameters available only as arguments of main would be a bad idea. But they should be settable, to account for the rare case of wanting to substitute something else to a library which reads them itself. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/

Marcin 'Qrczak' Kowalczyk
This suggests that making global parameters available only as arguments of main would be a bad idea. But they should be settable, to account for the rare case of wanting to substitute something else to a library which reads them itself.
Isn't it common for e.g. GUI frameworks to process argv[], interpreting and removing the arguments they use. So I'm not sure it is such a 'rare case'. (I guess you could do it differently in Haskell, e.g. have the library init return the list of updated args) -kzm -- If I haven't seen further, it is by standing in the footprints of giants
participants (2)
-
Ketil Malde
-
Marcin 'Qrczak' Kowalczyk