Reputation: 37
module Meth where
import System.Random
gen :: StdGen
gen = mkStdGen 42
shuffles:: StdGen->[(Int,Int)]
shuffles g = take 28(randoms g :: [Int])
I am trying to generate 28 random numbers I keep getting an error error
Couldn't match type ‘Int’ with ‘(Int, Int)’ Expected type: [(Int, Int)] Actual type: [Int] In the expression: take 28 $ randoms g :: [Int] In an equation for ‘shuffles’: shuffles g = take 28 $ randoms g :: [Int]
Upvotes: 1
Views: 321
Reputation: 64740
You explicitly say you are generating a list of Int
types:
... (randoms g :: [Int])
Then you also say you actually want a list of pairs of Int
s:
... -> [ (Int, Int) ]
Which do you want? If you want pairs then split your generator and zip up two separate calls to randoms
:
shuffles:: StdGen->[(Int,Int)]
shuffles g =
let (g1,g2) = split g
in take 28 $ zip (randoms g1) (randoms g2)
If you just want a list of Int
s then fix the incorrect type signature:
shuffles:: StdGen -> [Int]
shuffles g = take 28 (randoms g)
Upvotes: 2