[Haskell-cafe] Re: Can we come out of a monad?
Ertugrul Soeylemez
es at ertes.de
Wed Aug 11 07:39:13 EDT 2010
Martijn van Steenbergen <martijn at van.steenbergen.nl> wrote:
> On 8/2/10 7:09, Ertugrul Soeylemez wrote:
> > Given the definition of a Haskell function, Haskell is a pure
> > language. The notion of a function in other languages is not:
> >
> > int randomNumber();
> >
> > The result of this function is an integer. You can't replace the
> > function call by its result without changing the meaning of the
> > program.
>
> I'm not sure this is fair. It's perfectly okay to replace a call
> "randomNumber()" by that method's *body* (1), which is what you argue
> is okay in Haskell.
This is not the same. In Haskell you can replace the function call by
its /result/, not its body. You can always do that. But the result of
an IO-based random number generator is an IO computation, not a value.
It's not source code either, and it's not a function body. It's a
computation, something abstract without a particular representation.
This is what referential transparency is about. Not replacing function
calls by function bodies, but by their /results/. In C you can't
replace
putchar(33)
by
33
because that changes the program. Of course there are some exceptions
like many functions from math.h. Unlike Haskell you don't write a
program by using a DSL (like the IO monad), but you encode it directly
as a series of statements and function calls. C has no notion of a
"computation" the same way Haskell has.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
More information about the Haskell-Cafe
mailing list