BartC <b...@freeuk.com> writes: > 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).
I'm not sure what is installed by default. The place to look is the module System.Random: $ ghci GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help Prelude> import System.Random Prelude System.Random> getStdRandom random -4343223433618198958 If this does not work "out of the box" you need to use something like cabal to install System.Random. > Not an easy language..) Not an easy language to get started with, for sure. It is very different to the languages that most people have got used to. I image that people who learn it first have a different view (in more ways than one!). -- Ben. -- https://mail.python.org/mailman/listinfo/python-list