Dealing with configuration data

Liyang Hu liyang@nerv.cx
Thu, 26 Sep 2002 00:06:36 +0100


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

Evening,

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?

Cheers,
/Liyang
--=20
=2E--{ Liyang HU }--{ http://nerv.cx/ }--{ Caius@Cam }--{ ICQ: 39391385 }--.
| :: zettai unmei mokusiroku :::: absolute destined apocalypse ::::::::: |

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

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

iEYEARECAAYFAj2SQXwACgkQ1QR4EHtjLLjwHwCg7cZF+od6Ow+2xmBDVdN5W5K7
HaUAnjeTfReSxXfw02eat0sF0hgQStAi
=Oxsh
-----END PGP SIGNATURE-----

--mYCpIKhGyMATD0i+--