Do-notation associates to the right but, in the normalization magmoid, we mostly want to associate to the left in order to do observations. What we can do is to control associativity explicitly: it becomes the difference between updating and intervening.
conditionalSmoking :: Maybe (Distribution HasCancer)
conditionalSmoking = do
(gene, isSmoker) <- do
gene <- prevalence
isSmoker <- smokes gene
return (gene, isSmoker)
intervene (isSmoker == Smoker)
hasTar <- tar isSmoker
cancer <- health gene hasTar
return cancer
causalSmoking :: Maybe (Distribution HasCancer)
causalSmoking = do
gene <- prevalence
isSmoker <- smokes gene
intervene (isSmoker == Smoker)
hasTar <- tar isSmoker
cancer <- health gene hasTar
return cancerIn this fashion, we can do normalized probabilistic programming without a normalization operator: normalization is implicit in the order of composition.
Tags: normalization magmoid, do-notation.