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
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
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
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
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
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
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
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
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
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
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
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
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
| 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
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
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
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
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
> 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
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
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
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
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
23 matches
Mail list logo