I'm going through Learn You A Haskell and just finished the part "For a few monads more". In this part we created a `newtype Prob a = Prob { getProb :: [(a, Rational)] }` and created a `Monad` instance for it. This allows us to calculate probabilities of results in non-deterministic calculations like the following:

```
data Coin = Heads | Tails deriving (Show, Eq)

coin :: Prob Coin
coin = Prob [(Heads, 1%2), (Tails, 1%2)]

loadedCoin :: Prob Coin
loadedCoin = Prob [(Heads, 1%10), (Tails, 9%10)]

coinTest :: Prob Bool
coinTest = do
    a <- coin
    b <- coin
    c <- loadedCoin
    return (all (==Tails) [a,b,c])

```

Of course, this doesn't generate a very pretty result:

```
getProb coinTest
>> [(False,1 % 40),(False,9 % 40),(False,1 % 40),(False,9 % 40),(False,1 % 40),(False,9 % 40),(False,1 % 40),(True,9 % 40)]

```

It was left as an exercise to the reader to write a neat function to sum up all the `False`s and all the `True`s so we get `[(True,9 % 40),(False,31 % 40)]`. I've managed to do this, sort of. It works for this particular case, but I feel like it isn't a useful function at all since it's so specialized. Here's what I came up with:

```
sumProbs :: Prob Bool -> Prob Bool
sumProbs (Prob ps) = let (trues, falses) = partition fst ps
                         ptrue = reduce trues
                         pfalse = reduce falses
                     in Prob [ptrue, pfalse]
                     where reduce = foldr1 (\(b,r) (_,r') -> (b,r+r'))

```

I'd love to generalize it to work for any `Eq a => Prob a`, but so far no luck. I was thinking of maybe using a `Map` together with `unionWith` or something like that. Or maybe I can exploit the fact that `(a,b)` has a `Functor b` instance? I think I'm missing some simpler more elegant solution.

So, to sum it up: How can I write a function `sumProbs :: (Eq a) => Prob a -> Prob a` that sums up all the probabilities that share the same value (key)?