(==) :: a -> a -> Bool
ought to beeq1 :: a -> a -> Bool
eq1 _ _ = False
eq2 :: a -> a -> Bool
eq2 _ _ = True
eq1 = undefined
a -> b
can't be implemented
undefined
implementations)
f (f (f (f (f ..)))
Hello, can anyone help me out with this?
choose :: PickingMonad m => [a] -> m a
choose = undefined
- choose xs should run without error for any non-empty list xs :: [a] (for the empty list it can do anything)
- in the case of the monad m = IO, choose xs should run in time proportional to the length of xs
- in the case of the monad m = Dist, choose xs :: Dist a should compute a (not necessarily normalised)
distribution where each value in xs is assigned a probability proportional to the number of times it occurs in xs.
That is, prob xs x should be equal to k / n, where k = length [y | y <- xs, x == y] and n = length xs.
I have written the code in the way like this, not sure if its correct concept, but i get errors.
choose :: PickingMonad m => [a] -> m a
choose [] = error "Error"
choose xs = do
let n = length xs
i <- getRandomR (0, n-1)
return (xs !! i)