Add conflicts of interest to the InstanceGenerator and make some other cleanups.
[match/match.git] / program / RandomizedMonad.hs
index 37f2b98..f3b50d4 100644 (file)
@@ -3,9 +3,12 @@ module RandomizedMonad (
        runRandom, runRandomStd, runRandomNewStd,
        mrandomR, mrandom,
        withProb,
-       filterRandomized
+       filterRandomized,
+       indRandomArray
 ) where
 import System.Random
+import Data.Array.IArray
+import Data.Ix
 
 -- Needs -XRank2Types
 newtype Randomized a = Randomized (forall g. RandomGen g => (g -> a))
@@ -59,3 +62,11 @@ filterRandomized :: (a -> Bool) -> Randomized a -> Randomized a
 filterRandomized f ra = do
        a <- ra
        if f a then return a else filterRandomized f ra
+
+-- Randomized array with elements chosen independently following a given
+-- randomized element.
+indRandomArray :: (IArray a e, Ix i) =>
+       (i, i) -> Randomized e -> Randomized (a i e)
+indRandomArray bds rElement = do
+       list <- sequence $ replicate (rangeSize bds) rElement
+       return (listArray bds list)