[Haskell-cafe] On the purity of Haskell

Colin Adams colinpauladams at gmail.com
Fri Dec 30 18:20:53 CET 2011


On 30 December 2011 17:17, Gregg Reynolds <dev at mobileink.com> wrote:

>
> On Dec 30, 2011, at 11:04 AM, Colin Adams wrote:
>
>
>
> On 30 December 2011 16:59, Gregg Reynolds <dev at mobileink.com> wrote:
>
>>
>> On Fri, Dec 30, 2011 at 12:49 AM, Heinrich Apfelmus <
>> apfelmus at quantentunnel.de> wrote:
>>
>>>
>>> The function
>>>
>>>  f :: Int -> IO Int
>>>  f x = getAnIntFromTheUser >>= \i -> return (i+x)
>>>
>>> is pure according to the common definition of "pure" in the context of
>>> purely functional programming. That's because
>>>
>>>  f 42 = f (43-1) = etc.
>>>
>>> Put differently, the function always returns the same IO action, i.e.
>>> the same value (of type  IO Int) when given the same parameter.
>>>
>>
>>
>>
>> time t:  f 42   (computational process implementing func application
>> begins…)
>> t+1:   <keystroke> = 1
>> t+2:  43   (… and ends)
>>
>> time t+3:  f 42
>> t+4:  <keystroke> = 2
>> t+5:  44
>>
>> Conclusion:  f 42 != f 42
>>
>> (This seems so extraordinarily obvious that maybe Heinrich has something
>> else in mind.)
>>
>> This seems such an obviously incorrect conclusion.
>
> f42 is a funtion for returning a program for returning an int, not a
> function for returning an int.
>
>
> My conclusion holds:  f 42 != f 42.  Obviously, so I won't burden you with
> an explanation. ;)
>
> -Gregg
>
Your conclusion is clearly erroneous.

proof: f is a function, and it is taking the same argument each time.
Therefore the result is the same each time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111230/92ffcaee/attachment.htm>


More information about the Haskell-Cafe mailing list