\$\begingroup\$
\$\endgroup\$
0
Learn You a Haskell presents the randoms
function.
I implemented it as follows:
-- randoms that takes a generator and returns an infinite sequence
-- of values based on that generator
import System.Random
randoms' :: StdGen -> [Int]
randoms' g = num : randoms' gen
where (num, gen) = random g
Please critique it.
asked Jun 22, 2014 at 2:35
1 Answer 1
\$\begingroup\$
\$\endgroup\$
Straight forward. Easy to follow. But this is clearly some kind of fold.
randoms' = unfoldr (Just . random)
works nicely.
answered Jun 22, 2014 at 4:22
Explore related questions
See similar questions with these tags.
lang-hs