ICLP-DC12

281 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
281
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ICLP-DC12

  1. 1. Introduction Background Goal Current Status Results Conclusion . Implementation of a Gradual Polymorphic Type System with . Standard Subtyping for Prolog Spyros Hadjichristodoulou1 Stony Brook University Computer Science Department ICLP 2012 Doctorate ConsortiumSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 1 / 23
  2. 2. Introduction Background Goal Current Status Results ConclusionTypes in Prolog?Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 2 / 23
  3. 3. Introduction Background Goal Current Status Results ConclusionTypes in Prolog? . Theorem (Most Prolog Books) .. Prolog is an untyped language... .Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 2 / 23
  4. 4. Introduction Background Goal Current Status Results ConclusionTypes in Prolog? . Theorem (Most Prolog Books) .. Prolog is an untyped language... .Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 2 / 23
  5. 5. Introduction Background Goal Current Status Results ConclusionTypes in Prolog? . Theorem (Most Prolog Books) .. Prolog is an untyped language... .Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 2 / 23
  6. 6. Introduction Background Goal Current Status Results ConclusionTypes in Prolog?Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 3 / 23
  7. 7. Introduction Background Goal Current Status Results ConclusionTypes in Prolog?Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 3 / 23
  8. 8. Introduction Background Goal Current Status Results ConclusionTypes in Prolog?Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 3 / 23
  9. 9. Introduction Background Goal Current Status Results ConclusionOur vision A Gradual Polymorphic type system with SubtypingSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 4 / 23
  10. 10. Introduction Background Goal Current Status Results ConclusionOur vision A Gradual Polymorphic type system with Subtyping T . ype I .nference M . ore G . radual, U . . ntyped T . ypes T . ype I .ncremental P . rogram A . dded S . afe P . rocess P . ossibly U . nsafe T . ype C . hecking ( . user)Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 4 / 23
  11. 11. Introduction Background Goal Current Status Results ConclusionThe Mycroft-O’Keefe Type System . Example 1 .. :- type list(A) ---> [] ; [A|list(A)]. :- pred append(list(A),list(A),list(A)). append([],L,L). . append([X|L1],L2,[X|L3]) :- append(L1,L2,L3).Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 5 / 23
  12. 12. Introduction Background Goal Current Status Results ConclusionThe Mycroft-O’Keefe Type System . Example 1 .. :- type list(A) ---> [] ; [A|list(A)]. :- pred append(list(A),list(A),list(A)). append([],L,L). . append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). Prolog codeSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 5 / 23
  13. 13. Introduction Background Goal Current Status Results ConclusionThe Mycroft-O’Keefe Type System . Example 1 .. :- type list(A) ---> [] ; [A|list(A)]. :- pred append(list(A),list(A),list(A)). append([],L,L). . append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). Prolog code Type constructorSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 5 / 23
  14. 14. Introduction Background Goal Current Status Results ConclusionThe Mycroft-O’Keefe Type System . Example 1 .. :- type list(A) ---> [] ; [A|list(A)]. :- pred append(list(A),list(A),list(A)). append([],L,L). . append([X|L1],L2,[X|L3]) :- append(L1,L2,L3). Prolog code Type constructor Type signatureSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 5 / 23
  15. 15. Introduction Background Goal Current Status Results ConclusionOther works Towards Typed Prolog (Schrijvers, Santos Costa, Wielemaker, Demoen - 2009) Type inference by abstract interpretation (Barbuti,Giacobazzi 1990s)Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 6 / 23
  16. 16. Introduction Background Goal Current Status Results ConclusionOther works Towards Typed Prolog (Schrijvers, Santos Costa, Wielemaker, Demoen - 2009) Type inference by abstract interpretation (Barbuti,Giacobazzi 1990s)Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 6 / 23
  17. 17. Introduction Background Goal Current Status Results ConclusionOther works Towards Typed Prolog (Schrijvers, Santos Costa, Wielemaker, Demoen - 2009) Type inference by abstract interpretation (Barbuti,Giacobazzi 1990s) A . bstract P . redicate A . bstraction R . epresentation fi .x. Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 6 / 23
  18. 18. Introduction Background Goal Current Status Results ConclusionGoal Compile Load Execute XSB Disk .PSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 7 / 23
  19. 19. Introduction Background Goal Current Status Results ConclusionGoal User 1 c Compile Load Execute XSB Disk .PSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 7 / 23
  20. 20. Introduction Background Goal Current Status Results ConclusionGoal User 1 c Compile Load Execute XSB Disk Type 2 Analysis .P XSBSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 7 / 23
  21. 21. Introduction Background Goal Current Status Results ConclusionGoal User 1 c Compile Load Execute XSB T 3 Disk Type 2 Analysis .P XSBSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 7 / 23
  22. 22. Introduction Background Goal Current Status Results ConclusionGoal User 1 c Compile Load Execute XSB T 4 3 Disk Type 2 Analysis .P XSB E .xwamSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 7 / 23
  23. 23. Introduction Background Goal Current Status Results ConclusionGoal User 1 c Compile Load Execute XSB T 4 T 3 Disk Type 2 Analysis .P 5 XSB E .xwamSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 7 / 23
  24. 24. Introduction Background Goal Current Status Results ConclusionGoal User 1 c Compile Load 6 E Execute XSB T 4 T 3 Disk Type 2 Analysis .P 5 XSB E .xwamSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 7 / 23
  25. 25. Introduction Background Goal Current Status Results ConclusionExtensions (1) ⊤ integer float ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 8 / 23
  26. 26. Introduction Background Goal Current Status Results ConclusionExtensions (1) ⊤ c number t t t ) t ” integer float t t t t ” ) ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 8 / 23
  27. 27. Introduction Background Goal Current Status Results ConclusionExtensions (1) ⊤ c number t . t Example 2 t .. ) t ” foo(42). integer float . foo(4.2). t t t t ” ) ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 8 / 23
  28. 28. Introduction Background Goal Current Status Results ConclusionExtensions (1) ⊤ c number t . t Example 2 t .. ) t ” foo(integer). integer float . foo(float). t t t t ” ) ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 8 / 23
  29. 29. Introduction Background Goal Current Status Results ConclusionExtensions (1) ⊤ c number t . t Example 2 t .. ) t ” foo(number). integer float . t t t t ” ) ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 8 / 23
  30. 30. Introduction Background Goal Current Status Results ConclusionExtensions (2) ⊤ number atom t £ t £ ) t ” integer float £ £ t £ t £ t c£ ” t ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 9 / 23
  31. 31. Introduction Background Goal Current Status Results ConclusionExtensions (2) ⊤ c atomic t t ) t ” number atom t £ t £ ) t ” integer float £ £ t £ t £ t c£ ” t ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 9 / 23
  32. 32. Introduction Background Goal Current Status Results ConclusionExtensions (2) ⊤ c atomic t t . ) t ” Example 3 number atom .. t £ foo(42). t £ foo(4.2). ) t ” integer float £ . foo(bar). £ t £ t £ t c£ ” t ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 9 / 23
  33. 33. Introduction Background Goal Current Status Results ConclusionExtensions (2) ⊤ c atomic t t . ) t ” Example 3 number atom .. t £ foo(integer). t £ foo(float). ) t ” integer float £ . foo(atom). £ t £ t £ t c£ ” t ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 9 / 23
  34. 34. Introduction Background Goal Current Status Results ConclusionExtensions (2) ⊤ c atomic t t . ) t ” Example 3 number atom .. t £ foo(number). t £ ) t ” integer float £ . foo(atom). £ t £ t £ t c£ ” t ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 9 / 23
  35. 35. Introduction Background Goal Current Status Results ConclusionExtensions (2) ⊤ c atomic t t . ) t ” Example 3 number atom .. t £ foo(atomic). t £ ) t ” integer float £ . £ t £ t £ t c£ ” t ⊥Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 9 / 23
  36. 36. Introduction Background Goal Current Status Results ConclusionImplementation . General Idea .. 1: repeat 2: For a predicate H, let {H1 , . . . , Hn } be the heads of the clauses that define it 3: for all Hi ∈ {H1 , . . . , Hn } do 4: Let Hi : −Bi be the respective clause of H 5: for all B ∈ Bi do 6: Find the type of B and accumulate variable-type bindings for the entire clause 7: end for 8: The new type for H is the intersection of the types found for each Hi 9: end for .10: until No change is made to the inferred type for HSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 10 / 23
  37. 37. Introduction Background Goal Current Status Results ConclusionRemark A . 2 T .2 . . A . 1 T .1Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 11 / 23
  38. 38. Introduction Background Goal Current Status Results ConclusionAttempt #1 . Find type for a single clause .. type inference(Head,AssumList,Type) :- clause(Head,Body), get type(Head,Body,AssumList,PredType), if unify with occurs check(Type,PredType) then succeed else throw error . end ifSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 12 / 23
  39. 39. Introduction Background Goal Current Status Results ConclusionAttempt #1 . Inner fixed-point .. type inference batch(Head,AssumList,Type) :- findall(TypeInf, type inference(Head,AssumList,TypeInf), TList), . Unify all elements of TList wich each other to get TypeSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 13 / 23
  40. 40. Introduction Background Goal Current Status Results ConclusionAttempt #1 . Outer fixed-point .. do type inference batch(PList,AListIn,AListOut):- findall(TypeInf, (member(Head,PList), type inference batch(Pred,AListIn,TypeInf)), AListTemp), if AListIn != AListTemp then do type inference(PList,AListTemp,AListOut) else AListOut = AListIn . end ifSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 14 / 23
  41. 41. Introduction Background Goal Current Status Results ConclusionAttempt #2Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 15 / 23
  42. 42. Introduction Background Goal Current Status Results ConclusionAttempt #2Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 15 / 23
  43. 43. Introduction Background Goal Current Status Results ConclusionAttempt #2 . |?- f(X). .. f(21). f(42). f(84). . . Global Table ..Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 15 / 23
  44. 44. Introduction Background Goal Current Status Results ConclusionAttempt #2 . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f . (21).Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 15 / 23
  45. 45. Introduction Background Goal Current Status Results ConclusionAttempt #2 . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(21). f(42). .Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 15 / 23
  46. 46. Introduction Background Goal Current Status Results ConclusionAttempt #2 . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(21). f(42). f(84). .Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 15 / 23
  47. 47. Introduction Background Goal Current Status Results ConclusionAttempt #3Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 16 / 23
  48. 48. Introduction Background Goal Current Status Results ConclusionAttempt #3 Answer SubsumptionSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 16 / 23
  49. 49. Introduction Background Goal Current Status Results ConclusionAttempt #3 . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. Answer Subsumption Lattice operation: max/3Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 16 / 23
  50. 50. Introduction Background Goal Current Status Results ConclusionAttempt #3 . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(21). . Answer Subsumption Lattice operation: max/3Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 16 / 23
  51. 51. Introduction Background Goal Current Status Results ConclusionAttempt #3 . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(42). . Answer Subsumption Lattice operation: max/3Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 16 / 23
  52. 52. Introduction Background Goal Current Status Results ConclusionAttempt #3 . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(84). . Answer Subsumption Lattice operation: max/3Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 16 / 23
  53. 53. Introduction Background Goal Current Status Results ConclusionAttempt #3 . Type inference: tabling with answer subsumption .. type inference n(Head,Type) :- copy term1(Head,Type), numbervars(Type,0, ). type inference n(Head,Type) :- copy term(Head,Head1), clause(Head1,Body), get env(Body,Env), compute type(Env,Head1,Type1), copy term(Type1,Type), . numbervars(Type,0, ).Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 17 / 23
  54. 54. Introduction Background Goal Current Status Results ConclusionAttempt #3 . Lattice operation: unification .. type unify(X,Y,X1) :- unnumbervars(X,0,X1), unnumbervars(Y,0,Y1), X1 = Y1, . numbervars(X1,0, ).Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 18 / 23
  55. 55. Introduction Background Goal Current Status Results ConclusionResults (1) Name LOC # Def # Inf T(s) lib/pairlist.P 125 10 10 0.006 lib/lists.P 515 59 59 0.022 lib/ugraphs.P 850 90 90 0.102 lib/assoc xsb.P 566 49 48 0.029 lib/ordsets.P 422 39 39 0.023 examples/tree1k.P 2046 1 1 0.105Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 19 / 23
  56. 56. Introduction Background Goal Current Status Results ConclusionResults (2) . test.P .. :- type natural --- 0 ; s(natural). formula(0). formula(s(0)). formula(s(s(0))). formula(0 + s(0)). formula(s(s(0)) - s(0)). .Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 20 / 23
  57. 57. Introduction Background Goal Current Status Results ConclusionResults (2) . Result .. |?- infer constructors(’test.P’,formula( )). formula(natural). formula(+(natural,natural)). formula(-(natural,natural)). .Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 21 / 23
  58. 58. Introduction Background Goal Current Status Results ConclusionWhat’s next? D . eclaration Free T . . est/Debug M . odules M . etapredicatesSpyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 22 / 23
  59. 59. Introduction Background Goal Current Status Results Conclusion Thanks for your attention :-)Spyros Hadjichristodoulou Implementation of a Gradual Polymorphic Type System with Standard Subtyping for Prolog 23 / 23

×