
Evening all, Thanks for all the replies and suggestions! They've been extremely helpful. On Wed, Sep 25, 2002 at 04:34:02PM -0700, Hal Daume III wrote:
Okay, this is "bad" but I claim it's okay, iff it is used as in:
In the end, I opted for the global IORef through unsafePerformIO scheme; implicit parameters seemed too `bleedin' edge' for me... (that and I had in mind to also retro-fit the idea on top of WASH-CGI[0]; I don't want to make more changes than I absolutely have to.) (I haven't yet read John Hughes' paper on the topic though; that should be quite fun.) One thing to watch out for though: hGetContents is *not* your friend. At least it isn't if you're going to let it defer its work until you're inside modifyIORef... see the attached prefs.hs, line 28 onwards. Just for reference, I'm using GHC 5.02.2. I must have went almost insane trying to figure out why I was still getting the default settings, when every single line of the code seemed to state the contrary; I had already written up prefs.hs to post to the list to ask for help, when I noticed that if I put in the line ``mapM_ putStrLn kvs'' before I update the IORef, I get my new settings. If I leave it out, I get the defaults. Then it hit me -- hGetContents was lazily deferring its reads. A quickie alternative hGetLines seems to have fixed the problem. But I'm still not sure *why* that was a problem in the first place... Can anyone explain? (Looking at the library source didn't help.) Surely modifyIORef would have reduced kvs to head normal form (correct termino- logy?) just like putStrLn did? *sigh* This can't be good for my mental health. <g> Thanks everyone, /Liyang BTW: I'm on both the main and -cafe lists; you don't have to CC me. ^_- [0] http://www.informatik.uni-freiburg.de/~thiemann/WASH/ -- .--{ Liyang HU }--{ http://nerv.cx/ }--{ Caius@Cam }--{ ICQ: 39391385 }--. | ``Computer games don't affect kids, I mean if Pac Man affected us as | | kids, we'd all be running around in darkened rooms, munching pills and | | listening to repetitive music.'' |