如何编写具有以下类型签名的函数:
mySample :: StdGen -> Int -> [a] -> [a]
在方面
sample :: Int -> [a] -> RVar [a]
Data.Random.Exts中的样本定义在哪里?这里,sample是一个函数,它从给定的列表中返回一个随机子列表。
根据文档,这应该有效:
mySample :: StdGen -> Int -> [a] -> [a]
mySample g n xs = fst $ sampleState (sample n xs) g
然而,当我试图编译它时,我会遇到重叠的实例错误
mySample :: StdGen -> Int -> [a] -> [a]
mySample g n xs = evalState (runRVar (sample n xs) StdRandom) g