[Haskell] Re: Why is getArgs in the IO monad?
Jules Bean
jules at jellybean.co.uk
Tue Jan 18 03:10:45 EST 2005
On 18 Jan 2005, at 06:31, Jim Apple wrote:
> Tomasz Zielonka wrote:
>
>> I like to think that pure functions don't change between executions.
>
> I'd like to think they wouldn't change within executions. Is there a
> pure haskell way to check the value of a function between exections?
>
In principle, a haskell compiler might notice that a function is always
called with a particular argument, and inline the result of the
function at compile-time.
For example, you might well expect a program containing the subterm
"3+4" to be compiled into machine code which directly uses the constant
value 7. Certainly most decent C compilers will perform this
optimisation.
Such an optimisation, depends on the knowledge that "3+4" is always the
same value: i.e. that a pure function, given the same arguments, always
returns the same value (even between executions).
More sophisticated optimisation transforms might also depend on the
same property.
Whether GHC actually performs an optimisation along these lines I have
no idea.
Jules
More information about the Haskell
mailing list