10. Reasoning about programs
09/03/23
data Expr a = Var a
| Val Int
| Add (Expr a) (Expr a)
Add (Var 'x') (Val 1) :: Expr Char
instance Monad Expr wehere
-- return :: Expr a -> (a -> Expr b) -> Expr b
(Var v) >>= f = f v
(Value n) >>= f = Val n
(Add x y) >>= f = Add (x >>= f) (y >>= f)
Reasoning about programs
- How to do proofs about programs
- How to improve program efficiency
- Case study: compiler correctness
Equational Reasoning
One like distributive rule
...
= = .... =
Reasoning about Haskell
double :: Int -> Int
double x = x + x