Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. let f = fun(x) x in pair (f(3)) (f(true))
  2.  
  3. A = { 3:int, true:bool, pair: forall alf, beta. alf->beta->(alf x beta) }
  4.  
  5. AST:
  6.  
  7. Let:t12
  8. / | \
  9. / | \
  10. / | \
  11. f:* x:* apply:t11
  12. / \
  13. / \
  14. / \
  15. apply:t7 apply:t10
  16. / \ / \
  17. / \ / \
  18. / \ / \
  19. pair:<I> apply:t6 f:<I> true:bool
  20. / \
  21. / \
  22. f:<I> 3:int
  23.  
  24. *: GEN
  25. I: lookup(<ID>, A) and INST
  26.  
  27.  
  28. Derivation:
  29.  
  30. --------------------
  31. x:X |- x:X | {} (VAR)
  32. -------------------
  33. |- \x. x: X->X | {} (ABS) FTV(<empty env/context>) does not contain X
  34. -------------------
  35. |- (\x. x): forall X. X->X (GEN)
  36.  
  37. Hence, due to "Let f=fun(x) x in <body>", enter f: forall X. X->X into A.
  38.  
  39. A = { 3:int, true:bool, pair: forall alf, beta. alf->beta->(alf x beta), f: forall X. X->X }
  40.  
  41.  
  42. --------------- ---------------------
  43. A |- 3:int | {} A |- f:t41->t41 | {} (INST)
  44. ---------------------- ------------------- ------------------------------ --------------------------------------
  45. A |- true:bool | { } A |- f:t81->81 | {} A |- pair:a1->b1->(a1xb1) | {} A |- f 3:t6 | { t41->t41 = int -> t6 } (pair via INST)
  46. ------------------------------------------------------- -------------------------------------------------------------------------
  47. A |- f true :t10 | {t81->t81 = bool->t10} A |- pair f 3:t7 | { a1->b1->(a1xb1) = t6->t7 }
  48. ---------------------------------------------------------------------------------------------------------------------------------
  49. A |- pair (f 3) (f true):t11 | {t81->t81 = bool->t10, t41->t41 = int -> t6, a1->b1->(a1xb1) = t6->t7, t7 = t10->t11 }
  50. ---------------------------------------------------------------------------------------------------------------------------------
  51. A |- Let ... pair (f 4) (f true):t12 | {t81->t81 = bool->t10, t41->t41 = int -> t6, a1->b1->(a1xb1) = t6->t7, t7 = t10->t11, t12=t11 }
  52.  
  53.  
  54.  
  55. C = {t81->t81 = bool->t10, t41->t41 = int -> t6, a1->b1->(a1xb1) = t6->t7, t7=t10->t11, t12=t11}
  56. t = let f = \x.x in pair (f(3)) (f(true))
  57. S = t12
  58. T = SIGMA S
  59. X = { t81,t10,t41, t6, a1,b1, c1,t8, t11, t12}
  60.  
  61. Unification steps:
  62.  
  63. C = { t81 = bool, t81 = t10 , t41->t41 = int -> t6, a1->b1->(a1xb1) = t6->t7, t7=t10->t11, t12=t11 }
  64. SIGMA = {t81 |-> bool }
  65.  
  66. C = { bool = t10 , t41->t41 = int -> t6, a1->b1->(a1xb1) = t6->t7, t7=t10->t11, t12=t11 }
  67. SIGMA = { t10 |-> bool } o {t81 |-> bool }
  68.  
  69. C = { t41->t41 = int -> t6, a1->b1->(a1xb1) = t6->t7, t7=bool->t11, t12=t11 }
  70. C = { t41= int, t6 = int, a1->b1->(a1xb1) = t6->t7, t7=bool->t11, t12=t11 }
  71. SIGMA = { t41 |-> int} o { t6 |-> int} o { t10 |-> bool } o {t81 |-> bool }
  72. C = { a1->b1->(a1xb1) = int->t7, t7=bool->t11, t12=t11 }
  73.  
  74. C = { a1 = int, b1->(a1xb1) = t7, t7=bool->t11, t12=t11 }
  75. SIGMA = {a1 |-> int} o { t41 |-> int} o { t6 |-> int} o { t10 |-> bool } o {t81 |-> bool }
  76.  
  77. C = { b1->(intxb1) = t7, t7=bool->t11, t12=t11 }
  78. SIGMA = {t7 |-> b1->(intxb1) } o {a1 |-> int} o { t41 |-> int} o { t6 |-> int} o { t10 |-> bool } o {t81 |-> bool }
  79. C = { b1->(intxb1) = bool->t11, t12=t11 }
  80.  
  81. C = { b1 = bool, (intxb1) = t11, t12=t11 }
  82. SIGMA = {b1 |-> bool} o {t7 |-> b1->(intxb1) } o {a1 |-> int} o { t41 |-> int} o { t6 |-> int} o { t10 |-> bool } o {t81 |-> bool }
  83. C = { (intxbool) = t11, t12=t11 }
  84. SIGMA = { t11 |-> (intxbool) } o {b1 |-> bool} o {t7 |-> b1->(intxb1) } o {a1 |-> int} o { t41 |-> int} o { t6 |-> int} o { t10 |-> bool } o {t81 |-> bool }
  85. C = { (intxbool) = t12 }
  86. SIGMA = {t12 |-> (intxbool) } o { t11 |-> (intxbool) } o {b1 |-> bool} o {t7 |-> b1->(intxb1) } o {a1 |-> int} o { t41 |-> int} o { t6 |-> int} o { t10 |-> bool } o {t81 |-> bool }
  87.  
  88. T = SIGMA t12 = intxbool
  89.  
  90. Instead of using GEN and INST, you could also use LETPOLY (make copies), and ABSINF (assign new type to each copy).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement