Guest User

Untitled

a guest
Jul 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. -- EACC is obtained from CC by restricting functions to be affine and adding 3 constructs:
  2. -- - Put: `|x` marks a term without free affine variables.
  3. -- - Exp: `!x` is the type of `|x`.
  4. -- - Dup: `$v x y` replaces occurrences of `v` by `x` in `y`.
  5. -- With the following reduction rules:
  6. -- - nf(!a) => !nf(a)
  7. -- - nf(|a) => nf(a)
  8. -- - nf($x y z) => nf(z[y/x])
  9. -- With the following typing rules:
  10. -- - Γ |- x : t Γ |- t : * Γ |- x : !t Γ, x0 : t, ... xN : t |- y : u
  11. -- - ------------ ----------- --------------------------------------------
  12. -- - Γ |- |x : !t Γ |- !t : * Γ |- $v x y : u
  13. --
  14. -- Examples:
  15. -- (Note: I use `:->=` for clarity, but those characters are ignored.)
  16. --
  17. -- The type of Church nats is as expected, except for additional `!`s:
  18.  
  19. Nat = ∀ P : * -> !(P -> P) -> !(P -> P)
  20.  
  21. -- The number 3 is represented as:
  22.  
  23. c3 =
  24. Λ P : * ->
  25. λ s : !(P -> P) ->
  26. $ S = s
  27. | λ z : P ->
  28. S (S (S z))
  29.  
  30. -- Notice that:
  31. -- 1. `Λ` represents an erased lambda. Its variables are not affine.
  32. -- 2. The first `!` was used to allow the duplication of `s`.
  33. -- 3. `$ S = s in ...` was used to duplicate the `s` variable.
  34. -- 4. There is no free affine variable inside the expression inside `|`.
  35. -- 5. There is exactly one `|` between the declaration of S and its occurrences.
  36. -- 6. The term correctly type-checks as `∀ P : * -> !(P -> P) -> !(P -> P)`.
  37. -- 7. If you erase the `!`s, `|`s and `$`s, you get the usual CC definition.
  38. --
  39. -- The definitions of `add`, `mul` and `exp` are as follows:
  40.  
  41. exp =
  42. λ a : Nat ->
  43. λ b : !Nat ->
  44. Λ P : * ->
  45. $ B = b
  46. a !(P -> P) |(B P)
  47.  
  48. mul =
  49. λ a : Nat ->
  50. λ b : Nat ->
  51. Λ P : * ->
  52. λ s : !(P -> P) ->
  53. a P (b P s)
  54.  
  55. add =
  56. λ a : Nat ->
  57. λ b : Nat ->
  58. Λ P : * ->
  59. λ s : ! (P -> P) ->
  60. $ S = s
  61. $ f = (a P |S)
  62. $ g = (b P |S)
  63. | λ z : P ->
  64. f (g z)
  65.  
  66. -- Notice that all those functions correctly type check as `Nat -> Nat -> Nat`.
  67. -- Notice also that, again, erasing `!`s, `|`s and `$`s gives the usual CC definitions.
Add Comment
Please, Sign In to add comment