10

How do I write a function with a type signature like:

mySample :: StdGen -> Int -> [a] -> [a]

in terms of

sample :: Int -> [a] -> RVar [a]

where sample is defined in Data.Random.Extras? Here, sample is a function which returns a random sublist from the given list.

emchristiansen
  • 3,550
  • 3
  • 26
  • 40

1 Answers1

8

According to the documentation, this should work:

mySample :: StdGen -> Int -> [a] -> [a]
mySample g n xs = fst $ sampleState (sample n xs) g

However, I get overlapping instance errors when trying to compile it. I got this to compile, though:

mySample :: StdGen -> Int -> [a] -> [a]
mySample g n xs = evalState (runRVar (sample n xs) StdRandom) g
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
hammar
  • 138,522
  • 17
  • 304
  • 385