[Haskell-cafe] On the purity of Haskell
Gregg Reynolds
dev at mobileink.com
Thu Dec 29 21:20:07 CET 2011
On Dec 29, 2011, at 12:33 PM, Donn Cave wrote:
> Quoth Gregg Reynolds <dev at mobileink.com>,
> ..
>> A minor point maybe, but germane to the original post (I hope).
>
> It isn't - I mean, I'm not really sure what your point is, but
> the example really returns the same IO value, not just one of
> the same type.
>
> Consider an example with implementation:
>
> wint :: Int -> IO Int
> wint a = let s = show a in do
> putStr s
> return (length s)
>
> Now the expression "wint 994" is a value of type IO Int, and
> any instance of that expression is the same value
Ok, but if that were all there is to it we would not need monads. I guess it may boil down to a matter of taste in definition and exposition - to me any account of stuff like IO Int that omits mention of the fact that, well, IO is involved, is incomplete. But then I like the theoretical and even philosophical side of things where others tend to want to get on with writing useful code. ;) And the original post was if I remember about purity/impurity etc.
> - an action
> is not the same as the action's result.
Nor is a computation the same as the computation's result. The critical difference is that computations are deterministic processes, and "actions" (IO, rand, etc.) are not. Therefore they are not functions, their evaluation must be ordered, and they cannot even in principle be fully modeled in purely functional terms. At least I don't see how they can.
> You can use this
> value in pure Haskell expressions with confidence.
Because they are monadic, not because they are values like other values.
-Gregg
More information about the Haskell-Cafe
mailing list