[Hugs-users] Re: Excerpt from "Yet another Haskell Tutorial"

Johan Grönqvist johan.gronqvist at gmail.com
Sat Aug 5 11:05:09 EDT 2006


> 
> I'd like to ask a question concerning a following passage in
> "Yet another Haskell Tutorial" that ushers in the topic of monads:

I, as a beginner here, believe the haskell cafe list is the correct 
place for beginner questions.

> 
> <<After all, suppose you have a function that reads a string from the keyboard. Ifyou call this function twice, and the user types something the first time and something else the second time, then you no longer have a function, since it would return two different values.>>
> 
> How do I have to interpret this? I cannot make sense of it for I do not see where the definition of a function that I know is violated. 
> I view it that way: The string is just a kind of argument to the string-reading function and that different strings (i.e. different arguments) yield different return values is a commonplace phenomenon with functions, isn't it? How do I have to alter this (over?)simple interpretation to see the point the author wants to make?
> 

In this case I think you mean that the string typed on the keyboard is a 
  "kind of" argument to the function. I think this is the problem. A 
function call f x to a function f should always return the same value if 
  x is the same, and reading from keyboard and stating that the string 
read is a "kind of extra argument" to the function is not allowed. I 
think what is called functions here would be called "pure functions" ina 
different language. This would mean a function that only depends on its 
arguments.

Using this definition a zero-parameter function (like the readLine 
function mentioned above) must always return the same value. This 
property is violated.

This requirement makes Haskell a purely functional language.

/ johan



More information about the Hugs-Users mailing list