3
\$\begingroup\$

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
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

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
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.