[Haskell-cafe] On the purity of Haskell

Scott Turner 2haskell at pkturner.org
Thu Dec 29 23:47:47 CET 2011


On 2011-12-29 15:23, Gregg Reynolds wrote:
> On Dec 29, 2011, at 1:21 PM, Heinrich Apfelmus wrote:
> 
>> Why would  IO Int  be something special or mysterious?
> 
> I'm pretty sure IO is non-deterministic, non-computable, etc.  In other words not the same as computation.
> 
>> It's an ordinary value like everything else; it's on the same footing as [Char], Maybe Int, Int -> String, Bool, and so on. I see no difference between the list  [1,2,3] :: [Int]  and the action  "pick a random number between 1 and 6" :: IO Int  .
> 
> We'll have to agree to disagree - I see a fundamental difference.

You're misunderstanding the location of disagreement. We all know very
well how IO Int is special.

The example "pick a random number between 1 and 6" was unfortunate. I hope
    fmap read getLine :: IO Int
serves better.  The Haskell community says this expression indicates a
"value".  To be clear,
    fmap read getline
has the same value wherever it is written in a program or however many
times it is called, or however many different Int values it produces.
This definition of 'value' is at the heart of how we understand Haskell
to be referentially transparent and pure.

You can disagree, but if you hold that this expression does not have a
value until at execution time it produces an Int, then your
unconventional terminology will lead to confusion.

So what is the benefit of using Haskell?  Isn't
    fmap read getline
just as problematic as the C function
    gets()
regardless of whether you call it pure?  In Haskell, the type of
    fmap read getline
prevents it from being used in arbitrary parts of the program, so the
programmer or compiler can use the type to know whether a function is
performing I/O or other effects.



More information about the Haskell-Cafe mailing list