Yet Another Monad Tutorial
Tue, 12 Aug 2003 12:55:15 +0200
On Tuesday, 2003-08-12, 12:14, CEST, Alistair Bayley wrote:
> > Care to explain why you think Haskell is not pure?
> Purely functional = you are always defining and calling pure functions.
> Calling a pure function with the same arguments always gives the same
> results. In Haskell, if monadic state is used, then this is not true (there
> is support from the syntax + type system to hide the state argument). So
> Haskell's monadic state is an implementation of state *on top of* a purely
> functional language.
I wouldn't agree. In my opinion, in Haskell a function always gives the same
result when called with the same arguments, even if it involves I/O. So
Haskell is truely purely functional.
The point is that evaluating an expression of an IO type doesn't actually do
the I/O and yield the result of the I/O action. It yields a result which
*describes the action* to do. The I/O is only finally done because the
meaning of a Haskell program is to execute the action described by main.
For example, the function readFile is pure. For a specific string s the
expression readFile s always yields the same result: an I/O action which
searches for a file named s, reads its content and takes this content as the
result of the *action* (not the expression).
Correct me if I'm wrong. I wouldn't say that I'm an expert in these things.