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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With