[Haskell-beginners] Need help groking the statement: expression1 in term:expression2

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Tue Mar 22 11:38:10 UTC 2016


On 22-Mar-2016 4:14 pm, "Olumide" <50295 at web.de> wrote:
> randoms' :: (RandomGen g, Random a) => g -> [a]
> randoms' gen = let (value, newGen) = random gen in value:randoms' newGen

"random gen" returns a pair, whose first element is a random value, and the
second element is a new generator.

The cons (:) operator takes two values, one is an element, and the other is
a list. It returns a new list with the provided arguments as head and tail.

Ultimately, randoms' gen returns a list whose first element is a random
value, and the rest of the list is the result of calling randoms' on the
newly produced generator. Recursively, it generates an infinite lazy list
of random elements.

Hope this helps :)

Regards,
  Sumit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160322/24c73eb6/attachment.html>


More information about the Beginners mailing list