1
votes
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]

1
Unmatched parentheses on the last line. Voting to close as a typo.ApproachingDarknessFish
take 28 $ randoms g :: [Int]Johannes Kuhn
You're generating a list of Int and trying to return a list of (Int, Int).Lee
I put the parentheses but it still giving me an errorqwerty

1 Answers

2
votes

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 Ints:

... -> [ (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 Ints then fix the incorrect type signature:

shuffles:: StdGen -> [Int]
shuffles g = take 28 (randoms g)