Propositions as Types
See Philip Wadler’s classic talk on the subject. If you want more details, see the paper that goes along with it.
In class, we saw some facts about the propositional calculus.
$P \wedge Q \implies Q \wedge P$ $(P \implies Q \wedge Q \implies R) \implies (P \implies R)$ $((P \wedge Q) \wedge R) \implies (P \wedge (Q \wedge R))$ $(P \wedge (Q \vee R)) \implies (P \vee Q) \wedge (P \vee R)$
And we proved them in Haskell by coming up with a term (proof) of the appropriate type (proposition).
conjComm :: (b, a) -> (a, b) conjComm (p, q) = (q, p) implTrans :: ((a -> b), (b -> c)) -> (a -> c) implTrans (f, g) x = g (f x) conjAssoc :: ((a, b), c) -> (a, (b, c)) conjAssoc p = (fst (fst p), (snd (fst p), snd p)) distr :: (a, Either b c) -> Either (a, b) (a, c) distr (a, Left b) = Left (a, b) distr (a, Right c) = Right (a, c)