In the concurrency library GHC.Conc there is a function called numCapabilities. Its type is numCapabilities :: Int and it actually returns some number you passed by the command line flag (e.g. 5 if the options are +RTS -N 5).
However, getArgs (type: IO [String]) does essentially the same (it returns the unparsed non-runtime arguments) but isn’t a pure function.
If the only excuse is that numCapabilities is often needed in pure code, in what way aren’t other command line options not needed in pure code?
Am I something missing or is either numCapabilities a design flaw or am I allowed to write the following monster?
myGetArgs = unsafePerformIO getArgs
I’ve seen very varying views on what to do in situations like this. Some think that values that might vary between compiles should not be pure, and some think that as long as a value doesn’t change during your program’s local run-time (i.e. after some “configuration” has been “set up” in
main), it should be pure.The
basepackage seems to have settled on a middle-ground.numCapabilitieswill not (as far as I know) change during run-time, butgetArgsmight.This is because there is a
withArgsfunction that changes the args you get viagetArgs. So, that answers that.