module Boys where
import Probability
(Dist, Probability, Trans, Event,
uniform, just, mapD, sequ, (??), (|||))
data Child = Boy | Girl
deriving (Eq,Ord,Show)
type Family = [Child]
birth :: Trans Family
birth f = uniform [Boy:f,Girl:f]
family :: Dist Family
family = sequ [birth,birth] []
boys :: Int -> Event Family
boys n = just (replicate n Boy)
existsBoy :: Event Family
existsBoy = elem Boy
familyWithBoy :: Dist Family
familyWithBoy = family ||| existsBoy
twoBoys :: Probability
twoBoys = (boys 2) ?? familyWithBoy
countBoys :: Family -> Int
countBoys = length . filter (==Boy)
numBoys :: Dist Int
numBoys = mapD countBoys familyWithBoy