Simon L Peyton Jones wrote:
> The point is, if I *want* to have several behaviours in one run I can
> always use this second technique. But Haskell as it now stands prevents
> me from using the first, even when I *don't* want several behaviours in one
> run. I'd be prepared to pay the pain if I wanted the benefit. Since I
> don't want the "benefit" I don't want the pain.
>
That seems fair enough. Actually I have wanted to do things the first
way myself sometimes with other constant things than the environment,
but then I have just thought that that's not possible in principle, in
Haskell.
I see this environment stuff like a special case of some more general
problem. There are other constants that one might like to have as
constants in the program. For example, the date and time the program
started is also a constant and could reasonably be accessed as such.
(It could be in the environment, but in general it has to be read
into the program in some other way.)
So if it turns out to be possible to make the environment a constant,
it should open up possibilities for other constants as well. I
would rather see a general mechanism. Something like:
performOnceBeforeMain:: IO a -> a
timeStarted = performOnceBeforeMain (getCurrentTime)
Just like that one would do with unsafePerformIO, but with
safer semantics (hopefully) and blessed by Standard Haskell.
Then we wouldn't even need to change the environment to constant.
And we would have the benefit of having access to any other things
that are constant as well.
> This message has clarified that there are three (not two) reasons
> that argv should be constant
>
> 1. Easier programming
> 2. Faster running
> 3. Extra reasoning ability (this the new one; every call to
> f will behave the same way)
>
The only real problem I can think of right now, is that this -
I would really like to call it this paradigm shift - could complicate
implementation of persistent storage systems. But I feel quite
fuzzy about that anyway right now, so...
Sverker