[Haskell-cafe] On the purity of Haskell
Heinrich Apfelmus
apfelmus at quantentunnel.de
Thu Dec 29 20:26:12 CET 2011
Steve Horne wrote:
> Heinrich Apfelmus wrote:
>>
>> Again, purity refers to the semantics of functions (at run-time):
>> given the same argument, will a function always return the same
>> result? The answer to this question solely decides whether the
>> language is pure or impure. Note that this depends on the meaning of
>> "function" within that language. In C, side-effects are part of the
>> semantics of functions, so it's an impure language. In Haskell, on the
>> other hand, functions will always return the same result, so the
>> language is pure. You could say that side effects have been moved from
>> functions to some other type (namely IO) in Haskell.
>
> Anyway, if you're using IO actions, your code is not referentially
> transparent and is therefore impure - by your own definition of
> "impure". Causing side-effects may not be pedantically the issue, but
> the mix of causing and reacting to them - ie interacting with the
> "outside" - clearly means that some of your function results are
> dependent on what's happening "outside" your program. That includes
> side-effects "outside" your program yet caused by program program.
No, that's not my definition of "impure". Also, my Haskell code is
referentially transparent even though I'm using IO actions. If this
sounds paradoxical, then it's probably worth mulling about some more.
Maybe it helps to try to find an example of a function f :: A -> B for
some cleverly chosen types A,B that is not pure, i.e. does not return
the same values for equal arguments.
Chris Smith explains it very eloquently and Donn Cove and Jerzy
Karczmarczuk say the same thing.
Best regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
More information about the Haskell-Cafe
mailing list