Re: Dealing with configuration data

2002-09-26 Thread Koen Claessen
Hal Daume III suggested: | data Configuration = ... -- config data | | globalConfig :: IORef Configuration | globalConfig = unsafePerformIO (newIORef undefined) : | getConfig :: Configuration | getConfig = unsafePerformIO $ readIORef globalConfig : | main = do |...read

RE: Dealing with configuration data

2002-09-26 Thread Simon Peyton-Jones
| Sorry, I should also mention implicit parameters, if you're willing to use | that extension. I don't like them, though, and my impression from SPJ is | that it's very unclear whether they will get into Haskell 2 or not... It's *linear* implicit parameters that are a weird beast. Ordinary

Pure File Reading (was: Dealing with configuration data)

2002-09-26 Thread Koen Claessen
Dear all, At the moment, a discussion on haskell-cafe is going on about how to neatly program the fact that an entire program depends on a number of parameters that are read in once at the beginning of a program. The suggestion that many people came up with was using unsafePerformIO in the

Re: Pure File Reading (was: Dealing with configuration data)

2002-09-26 Thread Yoann Padioleau
Koen Claessen [EMAIL PROTECTED] writes: i find your idea very good. indeed for the library GetOpt, the argument of a program never change so it make sense to make this library without using IO monad, same for argv and for the enviroment. for openFile it seems harder, it would require to have a

Re: Dealing with configuration data

2002-09-26 Thread Nick Name
I just wrote a long and clear answer, but my e-mail client has crashed. I am going to change it (or to rewrite one in Haskell, grrr) but the answer will be shorter, I apologize. On Wed, 25 Sep 2002 16:34:02 -0700 (PDT) Hal Daume III [EMAIL PROTECTED] wrote: I don't mean to troll, but this

Re: Dealing with configuration data

2002-09-26 Thread Koen Claessen
Nick Name wrote: | The first idea from Koen Claessen (getConfig operates | directly on the file with unsafePerformIO) appears to | work, but this time we are *relying* on the fact that | the function will be evaluated once, since the file | could change and multiple evaluations of

Re: Dealing with configuration data

2002-09-26 Thread Nick Name
On Thu, 26 Sep 2002 16:02:01 +0200 (MET DST) Koen Claessen [EMAIL PROTECTED] wrote: In general, when using unsafePerformIO in this way, one wants to tell the compiler that it is not allowed to inline the expression. This can be done in most compilers by giving compiler pragma's. In the

Re: Dealing with configuration data

2002-09-26 Thread Hal Daume III
Koen, getConfig :: Configuration getConfig = unsafePerformIO $ do ...read configuration from file... return configuration (*) Actually, a Haskell compiler is free to inline these kind of expressions, so really one has to give a NOINLINE pragma to the compiler as well.

Re: Pure File Reading (was: Dealing with configuration data)

2002-09-26 Thread Lars Lundgren
On 26 Sep 2002, Yoann Padioleau wrote: Koen Claessen [EMAIL PROTECTED] writes: i find your idea very good. indeed for the library GetOpt, the argument of a program never change so it make sense to make this library without using IO monad, same for argv and for the enviroment. for

Re: Pure File Reading (was: Dealing with configuration data)

2002-09-26 Thread Yoann Padioleau
Lars Lundgren [EMAIL PROTECTED] writes: On 26 Sep 2002, Yoann Padioleau wrote: Koen Claessen [EMAIL PROTECTED] writes: i find your idea very good. indeed for the library GetOpt, the argument of a program never change so it make sense to make this library without using IO monad,

Re: Dealing with configuration data

2002-09-26 Thread Liyang Hu
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;