FlexInterpreter.agda 848 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. -- Andreas and James, Nov 2011 and Oct 2012
  2. -- {-# OPTIONS -v tc.lhs:20 -v tc.cover.top:20 #-}
  3. module FlexInterpreter where
  4. open import Common.MAlonzo
  5. data Ty : Set where
  6. nat : Ty
  7. arr : Ty -> Ty -> Ty
  8. data Exp : Ty -> Set where
  9. zero : Exp nat
  10. suc : Exp (arr nat nat)
  11. pred : Exp (arr nat nat)
  12. app : {a b : Ty} -> Exp (arr a b) -> Exp a -> Exp b
  13. data Nat : Set where
  14. zero : Nat
  15. suc : Nat -> Nat
  16. Sem : Ty -> Set
  17. Sem nat = Nat
  18. Sem (arr a b) = Sem a -> Sem b
  19. eval' : (a : Ty) -> Exp a -> Sem a
  20. eval' ._ zero = zero
  21. eval' ._ suc = suc
  22. eval' b (app f e) = eval' _ f (eval' _ e)
  23. eval' .(arr nat nat) pred zero = zero
  24. eval' ._ pred (suc n) = n
  25. eval : {a : Ty} -> Exp a -> Sem a
  26. eval zero = zero
  27. eval suc = suc
  28. eval pred zero = zero
  29. eval pred (suc n) = n
  30. eval (app f e) = eval f (eval e)
  31. main = mainDefault