Need help groking the statement: expression1 in term:expression2

Hello List, I'd appreciate help understanding the second line of following block of code (from LYH, first line added for completeness), http://learnyouahaskell.com/input-and-output#randomness randoms' :: (RandomGen g, Random a) => g -> [a] randoms' gen = let (value, newGen) = random gen in value:randoms' newGen The part I'm really struggling with is random gen in value:randoms' newGen Thanks, - Olumide

On Tue, Mar 22 2016 at 18:43:46 +0800, Olumide wrote:
Hello List,
I'd appreciate help understanding the second line of following block of code (from LYH, first line added for completeness),
http://learnyouahaskell.com/input-and-output#randomness randoms' :: (RandomGen g, Random a) => g -> [a] randoms' gen = let (value, newGen) = random gen in value:randoms' newGen
It's equivalent to the following: randoms' gen = let (value, newGen) = random gen in value:(randoms' newGen)
The part I'm really struggling with is random gen in value:randoms' newGen
Thanks,
- Olumide
-- Thanks, Quanyang

On 22-Mar-2016 4:14 pm, "Olumide" <50295@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
participants (3)
-
Olumide
-
Quanyang Liu
-
Sumit Sahrawat, Maths & Computing, IIT (BHU)