[Haskell-cafe] Solving the configuration problem with parametrized modules
jon.fairbairn at cl.cam.ac.uk
Tue Sep 6 15:01:17 CEST 2011
Joachim Breitner <mail at joachim-breitner.de> writes:
> Hi Cafe,
> this is an idea that has been floating in my head for a while, and I’m
> wondering about its feasibility and, if feasible, complexity (in the
> range from „trivial“ over “blog post” over “paper” to “thesis”).
> Application authors in Haskell often face the problem of run-time
> constants, e.g. values that are expected to be determined once during
> program start and then stay fixed for the remainder of the run. Good
> examples are user configuration values (--verbose, certain paths,
> debugging level, etc.).
There are two aspects to this, both of which have potential
solutions that I’ve been thinking about on and off for a long
The first is command line arguments.
As far as I’m concerned they ought to be passed as a parameter
to the whole programme. So instead of main being a value
exported to the outside world and all importing of values being
done through the IO monad, we would have main going out and
argv::[String] as a global variable (which, of course would not
change during any run of the programme). The alternative version
of this, to make main::[String] -> IO ExitCode has a superficial
cleanliness but doesn’t help with the general problem of having
to pass these things about, and in fact makes no real difference
to the referential transparancy of a programme.
The second is configuration data in files.
This seems to fall into two parts: the data that can be fixed at
link time and the data that changes from run to run. For the
former, a simple solution would be to have a facility to compile
a module from non-haskell data. This can be done with template
Haskell doing IO. So that leaves configuration data that changes
from run to run.
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html (updated 2010-09-14)
More information about the Haskell-Cafe