Dealing with configuration data

Hal Daume III hdaume@ISI.EDU
Wed, 25 Sep 2002 16:06:29 -0700 (PDT)


AFAIK, the global variable (so-called), passing around, and lifting the IO
monad are your only options.  I almost always use the global variable
method since I know that in this case the unsafePerformIO is actually
safe, since writing to the variable will always occur before the call to
upIO and that it will only be written once.  I don't feel bad about doing
this because GHC does this itself for its own configuration :).

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume

On Thu, 26 Sep 2002, Liyang Hu wrote:

> 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
> -- 
> .--{ Liyang HU }--{ http://nerv.cx/ }--{ Caius@Cam }--{ ICQ: 39391385 }--.
> | :: zettai unmei mokusiroku :::: absolute destined apocalypse ::::::::: |
>