On 05/10/2016 11:03, Ben Bacarisse wrote:
Gregory Ewing <greg.ew...@canterbury.ac.nz> writes:
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().
I suppose it all depends on what "that" is exactly. Here is the closest
match I could come up with:
import Control.Concurrent
spam io = do x <- io;
print x;
print (x+1)
main = spam (do threadDelay (2*10^6); return 1)
It matches the Python in that the delay happens once. To get the
behaviour being hinted at (two delays) you need to re-bind the IO
action:
spam io = do x <- io;
print x;
x <- io;
print (x+1)
(I downloaded Haskell (ghc) yesterday to try this out. First problem was
that I couldn't figure out how to do two things one after another
(apparently you need 'do').
And when I tried to use a random number function in an expression to see
if it was evaluated once or twice, apparently my installation doesn't
have any form of random() (despite being a monstrous 1700MB with 20,000
files).
Not an easy language..)
--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list