1
我一直試圖從序列中提取一個隨機元素。我試圖定義功能如下:從序列中提取隨機項目
getRandomInts :: Seq Int -> PureMT -> ((Seq Int, Int), PureMT)
getRandomInts ints gen = sampleState (fromJust $ choiceExtractSeq ints) gen
這是我的錯誤:
Overlapping instances for Data.Random.Lift.Lift
transformers-0.3.0.0:Data.Functor.Identity.Identity
(StateT PureMT transformers-0.3.0.0:Data.Functor.Identity.Identity)
arising from a use of `sampleState'
Matching instances:
instance [incoherent] (Monad m, MonadTrans t) =>
Data.Random.Lift.Lift m (t m)
-- Defined in `Data.Random.Lift'
instance [incoherent] Monad m =>
Data.Random.Lift.Lift
transformers-0.3.0.0:Data.Functor.Identity.Identity m
-- Defined in `Data.Random.Lift'
In the expression:
sampleState (fromJust $ choiceExtractSeq ints) gen
In an equation for `getRandomInt':
getRandomInt ints gen
= sampleState (fromJust $ choiceExtractSeq ints) gen
有誰知道如何解決這個問題,或者,有一個建議一個有效率從序列中取一個隨機元素(沒有替換)的方法?
另一種方法是通過用'(runState.ampleRVar)'替換'sampleState'來避免'Lift'(我喜歡完全停止使用它,它總是會導致這樣的問題)。後一個函數在'Data.RVar'模塊中,它稍低一些,並且不使用'Lift'。 – mokus