Assignment versus binding

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Oct 5 02:04:11 EDT 2016


Steve D'Aprano wrote:

> And (shamelessly using Python syntax) if I have a function:
> 
> def spam(x):
>     print(x)
>     print(x+1)
 >
 > spam(time.sleep(60) or 1)

You can't write that in Haskell, because Haskell's
equivalent of print() is not a function (or at least
it's not a function that ever returns), and neither
is sleep().

It's hard to explain without going into a lot of
detail about monads, but if you tried to write that
in Haskell you would find that the type system,
together with the way the I/O "functions" are defined,
makes it impossible to write anything that uses the
return value of an expression that performs an I/O
operation. So "time.sleep(60) or 1" is unwriteable,
because the return value of the sleep() is not
accessible.

-- 
Greg



More information about the Python-list mailing list