Dealing with configuration data

Liyang Hu
Thu, 26 Sep 2002 00:06:36 +0100

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable


I'm trying to write a utility that reads in some user preferences from
a pre-determined file, does some work, and exits. Sounds simple enough.

The problem I'm having is with the preferences: How do I make it
available throughout the entire program? (FWIW, most of the work is
effectively done inside the IO monad.) I could explicitly pass the
record around everywhere, but that seems a trifle inelegant.

My current solution is to use a global ('scuse my terminology, I'm not
sure that's the right word to use here) variable of type IORef Config
obtained through unsafePerformIO. It works, but strikes me as a rather
barbaric solution to a seemingly tame enough problem...

Intuition tells me I should be able to `embed', if you will, the config
record somehow within or alongside the IO state, and retrieve it at
will. (Is this what MonadState is for?) However it also tells me that
this will /probably/ involve lots of needless lifting and rewriting of
the existing code, which makes it even less enticing than passing
everything around explicitly.

Any opinions or suggestions?

=2E--{ Liyang HU }--{ }--{ Caius@Cam }--{ ICQ: 39391385 }--.
| :: zettai unmei mokusiroku :::: absolute destined apocalypse ::::::::: |

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.0.6 (GNU/Linux)
Comment: moo! (ID: 7B632CB8)