Clear all warnings
This commit is contained in:
@@ -3,7 +3,7 @@ Helpers for random generation.
|
||||
-}
|
||||
module Dodge.RandomHelp where
|
||||
import Geometry
|
||||
import Geometry.Data
|
||||
--import Geometry.Data
|
||||
|
||||
import System.Random
|
||||
import Control.Monad.State
|
||||
@@ -20,15 +20,15 @@ takeOne xs = state (randomR (0,length xs - 1)) >>= (\i -> return (xs !! i))
|
||||
|
||||
takeOneWeighted :: (RandomGen g, Random b, Ord b, Num b) => [b] -> [a] -> State g a
|
||||
takeOneWeighted ws xs = state (randomR (0, sum ws))
|
||||
>>= (\w -> return (xs !! i w ws))
|
||||
>>= (\w -> return (xs !! i w ws))
|
||||
where
|
||||
i y (z:zs)
|
||||
| y <= z = 0
|
||||
| otherwise = 1 + i (y-z) zs
|
||||
i y _ = 0
|
||||
i _ _ = 0
|
||||
|
||||
takeOneMore :: RandomGen g => ([a],[a]) -> State g ([a],[a])
|
||||
takeOneMore (xs,[]) = error "trying to takeOneMore from empty list"
|
||||
takeOneMore ( _,[]) = error "trying to takeOneMore from empty list"
|
||||
takeOneMore (xs,ys) = do
|
||||
i <- state $ randomR (0,length ys - 1)
|
||||
let (zs, w:ws) = splitAt i ys
|
||||
@@ -38,7 +38,7 @@ takeNMore :: RandomGen g => Int -> ([a],[a]) -> State g ([a],[a])
|
||||
takeNMore n p = foldr (const (>>= takeOneMore)) (return p) [1..n]
|
||||
|
||||
takeN :: RandomGen g => Int -> [a] -> State g [a]
|
||||
takeN 0 xs = return []
|
||||
takeN 0 _ = return []
|
||||
takeN i xs = fst <$> takeNMore i ([],xs)
|
||||
|
||||
-- | Randomly shuffle a list.
|
||||
@@ -54,6 +54,7 @@ shuffle xs = do
|
||||
-- | Randomly shuffle the tail of a list, not safe.
|
||||
shuffleTail :: RandomGen g => [a] -> State g [a]
|
||||
shuffleTail (x:xs) = (x :) <$> shuffle xs
|
||||
shuffleTail _ = undefined
|
||||
|
||||
randomSelectionFromList :: RandomGen g => Float -> [a] -> State g [a]
|
||||
randomSelectionFromList p = filterM $ const $ randProb p
|
||||
|
||||
Reference in New Issue
Block a user