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

2002-10-11 Thread Hal Daume III
This message seems to have been lost and I'd like to try to breathe some life into it. First, a question: could such "readFilePure" functions be implemented on TOP of the current IO module (perhaps in IO.Pure or something). Of course, one could do something like: readFileOnce :: FilePath -> Ma

Re: Dealing with configuration data

2002-09-28 Thread Andrew J Bromage
G'day all. On Fri, Sep 27, 2002 at 12:56:38PM -0400, Dean Herington wrote: > I'm not sure why you consider the code you refer to above so ugly. Anything which relies on unsafePerformIO (or seq, for that matter) is ugly. Personal opinion, of course. :-) > Question: > Why do you use `seq` on `g

Re: Dealing with configuration data

2002-09-27 Thread Dean Herington
Andrew J Bromage wrote: > There's also a much uglier solution which I occasionally use if I > need an "ad hoc" global variable. Rather than using IORefs, I use > Strings as keys. The code is here: > > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/hfl/hfl/ioext/ I'm not sure why you co

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; imp

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

2002-09-26 Thread oleg
There is another solution to the problem of configurational parameters. The main part of the solution is portable, does not depend on any pragmas, does not use unsafe operations, does not use implicit parameters, and does not require any modifications to the user code. I must warn that it is also

RE: Dealing with configuration data

2002-09-26 Thread John Hughes
On Thu, 26 Sep 2002, Simon Peyton-Jones wrote: > | 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... > I wrote a s

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 we

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

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 readConfig

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 usi

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. > f

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: 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

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 impli

Pure File Reading (was: Dealing with configuration data)

2002-09-25 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 begin

Re: Dealing with configuration data

2002-09-25 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 configuratio

Re: Dealing with configuration data

2002-09-25 Thread Andrew J Bromage
G'day all. On Thu, Sep 26, 2002 at 12:06:36AM +0100, Liyang Hu wrote: > 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 ever

Re: Dealing with configuration data

2002-09-25 Thread Hal Daume III
I don't mean to troll, but this isn't what I meant. Suppose we have: data Configuration = ... -- config data globalConfig :: IORef Configuration globalConfig = unsafePerformIO (newIORef undefined) Now, we define an unsafe function to read the configuration: getConfig :: Confi

Re: Dealing with configuration data

2002-09-25 Thread Jorge Adriano
> 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 i

Re: Dealing with configuration data

2002-09-25 Thread Nick Name
On Wed, 25 Sep 2002 16:06:29 -0700 (PDT) Hal Daume III <[EMAIL PROTECTED]> wrote: > I don't feel bad about doing > this because GHC does this itself for its own configuration :). I am going to show you that using unsafePerformIO where there really are side effects leads to unpredictable results

Re: Dealing with configuration data

2002-09-25 Thread Hal Daume III
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... -- Hal Daume III "Computer science is no more about computers| [EMAIL PR

Re: Dealing with configuration data

2002-09-25 Thread Hal Daume III
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 t

Dealing with configuration data

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