I'm a complete newbie currently trying to learn Haskell with "Learn You a Haskell for Great Good". I've reach the section explaining how to work with command line arguments, and something is bugging me.
From my understanding (and haskell.org's definition), actions are meant to encapsulate side effects. Command line arguments being immutable inputs for a given instance of the program, then what is the point of having getProgName :: IO String
rather than getProgName :: String
? Differently put: what's the point of preventing a pure function from calling getProgName
?
Update
I had some great answers to this question so far. I'm accepting Don Stewart's as the most simple and concise, but Conal's (with its associated blog post) is definitely worth a read.
Firstly, getArgs
can change at runtime. See withArgs
.
Secondly, getArgs
and getProgName
fall into an interesting class of impure computations - they are thought of as constants during a program run, however, they're are not values available at compile time, and they change from one program run to another. They don't have a clean denotation.
See e.g. earlier discussions, where getArgs, and floating point computations are discussed. And even minBound/maxBound can be thought to be in this class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With