SlideShare a Scribd company logo
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion




      .
                    Implementation of a Gradual
                   Polymorphic Type System with
      .
                   Standard Subtyping for Prolog

                                        Spyros Hadjichristodoulou
                                           David S. Warren1

                                               Stony Brook University
                                            Computer Science Department


                                                     WLPE 2012



Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    1 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Types in Prolog?




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    2 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Types in Prolog?


      .
      Theorem (Most Prolog Books)
     ..
      Prolog is an untyped language...
      .




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    2 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Types in Prolog?


      .
      Theorem (Most Prolog Books)
     ..
      Prolog is an untyped language...
      .




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    2 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Types in Prolog?


      .
      Theorem (Most Prolog Books)
     ..
      Prolog is an untyped language...
      .




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    2 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Previous works


              Mycroft-O’Keefe’s type system (DEC-10)
              Mercury, Visual Prolog
              Type inference by abstract interpretation (Barbuti,Giacobazzi
              - 1990s)
              Towards typed Prolog (Schrijvers, Santos Costa, Wielemaker,
              Demoen - 2009)




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    3 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Previous works


              Mycroft-O’Keefe’s type system (DEC-10)
              Mercury, Visual Prolog
              Type inference by abstract interpretation (Barbuti,Giacobazzi
              - 1990s)
              Towards typed Prolog (Schrijvers, Santos Costa, Wielemaker,
              Demoen - 2009)
              Why do Prolog vendors still keep it type-free?




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    3 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Our vision
      A Gradual Polymorphic type system with Subtyping




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    4 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Our 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 David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    4 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The 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 David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    5 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The 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




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    5 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The 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




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    5 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The 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 signature




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    5 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Towards Typed Prolog (2009)



              Implementation of the Mycroft-O’Keefe type system
              For SWI-Prolog and YAProlog
              Type checking
              Interaction between typed and untyped code
              Typed Prolog vs untyped Prolog




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    6 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Type inference by abstract interpretation
(1990s)



                          A
                          . bstract
       P
       . redicate                      A
                                       . bstraction
                       R
                       . epresentation
                                            fi
                                            .x
              Extension with type union
              Able to type metapredicates (univ/2)




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    7 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



ActionScript and Erlang


      ActionScript:
              Gradual type systems: mixing static and dynamic type
              checking
              User has control over portion of program statically checked
              Recently added type inference
      Erlang:
              Dialyzer tool for static analysis
              Gradually applied Dialyzer to Wrangler




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    8 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (1)
                                   ⊤




                   integer                  float




                                   ⊥


Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    9 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (1)
                                   ⊤


                                     c
                               number
                                       t
                                        t
                                         t
                         
                         )                 t
                                           ”
                   integer                  float
                         t                    
                          t                  
                           t             
                            t
                            ”           
                                        )
                                   ⊥


Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    9 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (1)
                                   ⊤


                                     c
                               number
                                       t                        .
                                        t                       Example 2
                                         t                     ..
                         
                         )                 t
                                           ”                       foo(42).
                   integer                  float                . foo(4.2).
                         t                    
                          t                  
                           t             
                            t
                            ”           
                                        )
                                   ⊥


Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    9 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (1)
                                   ⊤


                                     c
                               number
                                       t                        .
                                        t                       Example 2
                                         t                     ..
                         
                         )                 t
                                           ”                       foo(integer).
                   integer                  float                . foo(float).
                         t                    
                          t                  
                           t             
                            t
                            ”           
                                        )
                                   ⊥


Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    9 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (1)
                                   ⊤


                                     c
                               number
                                       t                        .
                                        t                       Example 2
                                         t                     ..
                         
                         )                 t
                                           ”
                                                                      foo(number).
                   integer                  float                 .
                         t                    
                          t                  
                           t             
                            t
                            ”           
                                        )
                                   ⊥


Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog    9 / 23
Introduction       Background       Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (2)
                              ⊤




                   number           atom
                      t           £
                       t         £
             
             )           t
                         ”
      integer            float £
                                £
             t                 £
              t               £
               t           c£
                ”
                t
                            ⊥



Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   10 / 23
Introduction       Background       Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (2)
                              ⊤

                               c
                           atomic
                                t
                                 t
                       )
                                  t
                                   ”
                   number           atom
                      t           £
                       t         £
             
             )           t
                         ”
      integer            float £
                                £
             t                 £
              t               £
               t           c£
                ”
                t
                            ⊥



Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   10 / 23
Introduction       Background       Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (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 David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   10 / 23
Introduction       Background       Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (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 David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   10 / 23
Introduction       Background       Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (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 David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   10 / 23
Introduction       Background       Extensions      Type Inference      Implementation        Results      Conclusion



Extensions (2)
                              ⊤

                               c
                           atomic
                                t
                                 t                              .
                       )
                                  t
                                   ”                             Example 3
                   number           atom                        ..
                      t           £                                  foo(atomic).
                       t         £
             
             )           t
                         ”
      integer            float £                                  .
                                £
             t                 £
              t               £
               t           c£
                ”
                t
                            ⊥



Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   10 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The struct type


      .
      lookup/3
     ..




      .




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   11 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The struct type


      .
      lookup/3
     ..
        :- type list(A) --- [] ; [A|list(A)].




      .




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   11 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The struct type


      .
      lookup/3
     ..
        :- type list(A) --- [] ; [A|list(A)].



        lookup([], ,0).
      . lookup([X’=’Y|T],X,Y) :- atom(X),integer(Y),lookup(T, , ).




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   11 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The struct type


      .
      lookup/3
     ..
        :- type list(A) --- [] ; [A|list(A)].

          :- pred lookup(list(struct),atom,integer).

        lookup([], ,0).
      . lookup([X’=’Y|T],X,Y) :- atom(X),integer(Y),lookup(T, , ).




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   11 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The struct type


      .
      lookup/3
     ..
        :- type list(A) --- [] ; [A|list(A)].
        :- type pair(A,B) --- A (=) B.
        :- pred lookup(list(struct),atom,integer).

        lookup([], ,0).
      . lookup([X’=’Y|T],X,Y) :- atom(X),integer(Y),lookup(T, , ).




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   11 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The struct type


      .
      lookup/3
     ..
        :- type list(A) --- [] ; [A|list(A)].
        :- type pair(A,B) --- A (=) B.
        :- pred lookup(list(pair(atom,integer),atom,integer)).

        lookup([], ,0).
      . lookup([X’=’Y|T],X,Y) :- atom(X),integer(Y),lookup(T, , ).




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   11 / 23
Introduction      Background        Extensions      Type Inference                         Implementation   Results   Conclusion



Subtyping relation
                                                                    ⊤
                                                                           d
                                                             
                                                            ©               ‚
                                                                            d
                                              atomic                                           struct
                                                    t                                                     ¢
                                                     t                                                ¢
                                            
                                            )          t
                                                       ”                                           ¢
                                    number            atom
                                                                                               ¢
                                           t                                              ¢
                                            t                                         ¢
                                )
                                             t
                                              ”                                    ¢
                          integer           float
                                                                               ¢
                                     t                                    ¢
                                      t
                                                                      ¢
                                       ”
                                        t                 c        ¢
                                     
                                     ~
                                                                 
                                                                  ¢
                                                        ⊥


Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog              12 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The cult of the bound variable




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   13 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The cult of the bound variable


              Why even bother doing type inference?




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   13 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The cult of the bound variable


              Why even bother doing type inference?
              Similar method to “Type inference by abstract interpretation”




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   13 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The cult of the bound variable


              Why even bother doing type inference?
              Similar method to “Type inference by abstract interpretation”
              Infrastructure taken by “Towards Typed Prolog”




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   13 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The cult of the bound variable


              Why even bother doing type inference?
              Similar method to “Type inference by abstract interpretation”
              Infrastructure taken by “Towards Typed Prolog”
              Type variables vs Prolog variables




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   13 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The cult of the bound variable


              Why even bother doing type inference?
              Similar method to “Type inference by abstract interpretation”
              Infrastructure taken by “Towards Typed Prolog”
              Type variables vs Prolog variables

                          A
                          . 2                                                         T
                                                                                      .2
                .                                                          .
              A
              . 1                                                         T
                                                                          .1




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   13 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The idea
      .
      General Idea
     ..
        repeat
          For a predicate H, let {H1 , . . . , Hn } be the heads of the
          clauses that define it
          for all Hi ∈ {H1 , . . . , Hn } do
             Let Hi : −Bi be the respective clause of H
             for all B ∈ Bi do
                Find the type of B and accumulate variable-type bindings
                for the entire clause
             end for
             The new type for H is the intersection of the types found
             for each Hi
          end for
      . until No change is made to the inferred type for H

Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   14 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).


        Type




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 1

        Type




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 1

        Type




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 1
        member(A,list(A))
       Type




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 1
        member(A,list(A))
       Type




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 1
        member(A,list(A)) member(B,list(C))
       Type




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 1
        member(A,list(A)) member(B,list(C))
       Type         member(A,list(A))



Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 1

        Type          member(A,list(A))




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 2

        Type          member(A,list(A))




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 2

        Type          member(A,list(A))




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 2
        member(A,list(A))
       Type member(A,list(A))




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 2
        member(A,list(A))
       Type member(A,list(A))




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 2
        member(A,list(A))    member(B,list(B))
       Type member(A,list(A))




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



An example


      .
      Example 4: member/2
     ..
        :- type list(A) --- [] ; [A|list(A)].

        member(X,[X| ]).
      . member(X,[ |T]) :- member(X,T).
        Iteration 2
        member(A,list(A))     member(B,list(B))
       Type         member(B,list(B))



Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   15 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Overview




                   Compile                            Load                              Execute

         XSB

                                                     Disk
                                                            .P




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   16 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Overview

         User
         1
           c
                   Compile                            Load                              Execute

         XSB

                                                     Disk
                                                            .P




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   16 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Overview

         User
         1
           c
                    Compile                           Load                              Execute

         XSB

                                                     Disk
                      Type                    2
                     Analysis '                             .P
                   XSB




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   16 / 23
Introduction        Background      Extensions      Type Inference      Implementation        Results      Conclusion



Overview

         User
         1
           c
                    Compile                           Load                              Execute

         XSB            T

                    3                                Disk
                      Type                    2
                     Analysis '                             .P
                   XSB




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   16 / 23
Introduction        Background      Extensions      Type Inference      Implementation        Results      Conclusion



Overview

         User
         1
           c
                    Compile                           Load                              Execute

         XSB            T        4

                    3                                Disk
                      Type                    2
                     Analysis '                             .P
                   XSB                                E .xwam




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   16 / 23
Introduction        Background      Extensions      Type Inference      Implementation        Results      Conclusion



Overview

         User
         1
           c
                    Compile                           Load                              Execute

         XSB            T        4                            T

                    3                                Disk
                      Type                    2
                     Analysis '                             .P 5
                   XSB                                E .xwam




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   16 / 23
Introduction        Background      Extensions      Type Inference      Implementation        Results      Conclusion



Overview

         User
         1
           c
                    Compile                           Load 6                    E       Execute

         XSB            T        4                            T

                    3                                Disk
                      Type                    2
                     Analysis '                             .P 5
                   XSB                                E .xwam




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   16 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling


      .
      |?- f(X).
     ..
      f(21).
      f(42).
      f(84).
      .
      .
      Global Table
     ..




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   17 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling


      .
      |?- f(X).
     ..
      f(21).
      f(42).
      f(84).
      .
      .
      Global Table
     ..
      f
      . (21).




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   17 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling


      .
      |?- f(X).
     ..
      f(21).
      f(42).
      f(84).
      .
      .
      Global Table
     ..
      f(21).
      f(42).
      .




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   17 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling


      .
      |?- f(X).
     ..
      f(21).
      f(42).
      f(84).
      .
      .
      Global Table
     ..
      f(21).
      f(42).
      f(84).
      .



Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   17 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling with Answer Subsumption




                                                                  Answer Subsumption




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   18 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling with Answer Subsumption


      .
      |?- f(X).
     ..
      f(21).
      f(42).
      f(84).
      .
      .
      Global Table
     ..
                                                                  Answer Subsumption
                                                                  Lattice operation: max/3




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   18 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling with Answer Subsumption


      .
      |?- f(X).
     ..
      f(21).
      f(42).
      f(84).
      .
      .
      Global Table
     ..
      f(21).
      .                                                           Answer Subsumption
                                                                  Lattice operation: max/3




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   18 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling with Answer Subsumption


      .
      |?- f(X).
     ..
      f(21).
      f(42).
      f(84).
      .
      .
      Global Table
     ..
      f(42).
      .                                                           Answer Subsumption
                                                                  Lattice operation: max/3




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   18 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Tabling with Answer Subsumption


      .
      |?- f(X).
     ..
      f(21).
      f(42).
      f(84).
      .
      .
      Global Table
     ..
      f(84).
      .                                                           Answer Subsumption
                                                                  Lattice operation: max/3




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   18 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The code (1)

      .
      Type inference: tabling with answer subsumption
     ..
        type inference n(Head,Type) :-
         copy term1(Head,Type),
         numbervars(Head,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 David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   19 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



The code (2)



      .
      Lattice operation: unification
     ..
        type unify(X,Y,X1) :-
         unnumbervars(X,0,X1),
         unnumbervars(Y,0,Y1),
         X1 = Y1,
      . numbervars(X1,0, ).




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   20 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



Results (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.105




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   21 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion



What’s next?


                                                                           D
                                                                           . eclaration Free

        T     .
        . est/Debug


                                              M
                                              . odules

                                                                            M
                                                                            . etapredicates




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   22 / 23
Introduction      Background        Extensions      Type Inference      Implementation        Results      Conclusion




      Thanks for your attention :-)




Spyros Hadjichristodoulou David S. Warren       Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog   23 / 23

More Related Content

Viewers also liked

Prolong tutorial
Prolong tutorialProlong tutorial
Prolong tutorialyurimendoz
 
Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL AnimationKiran Munir
 
Expert Systems & Prolog
Expert Systems & PrologExpert Systems & Prolog
Expert Systems & Prolog
Fatih Karatana
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Ankit Kumar
 
Prolog programming
Prolog programmingProlog programming
Prolog programming
Harry Potter
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
Arvind Devaraj
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
wahab khan
 
Predicate Calculus
Predicate CalculusPredicate Calculus
Predicate Calculus
Serge Garlatti
 
Interestingand unusual
Interestingand unusualInterestingand unusual
Interestingand unusual
Hamdy Attia
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
Vivek Kumar Sinha
 
Computer Graphics Project Development Help with OpenGL computer graphics proj...
Computer Graphics Project Development Help with OpenGL computer graphics proj...Computer Graphics Project Development Help with OpenGL computer graphics proj...
Computer Graphics Project Development Help with OpenGL computer graphics proj...
Team Codingparks
 
Introduction to Prolog
Introduction to PrologIntroduction to Prolog
Introduction to Prolog
Chamath Sajeewa
 
تشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائيتشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائي
محمد الجمل
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligenceiarthur
 
Leveraging Symfony2 Forms
Leveraging Symfony2 FormsLeveraging Symfony2 Forms
Leveraging Symfony2 Forms
Bernhard Schussek
 
Advanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems SolutionAdvanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems Solution
Joe Christensen
 
Computer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithmComputer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithm
RAJEEV KUMAR SINGH
 

Viewers also liked (18)

Prolong tutorial
Prolong tutorialProlong tutorial
Prolong tutorial
 
Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL Animation
 
Expert Systems & Prolog
Expert Systems & PrologExpert Systems & Prolog
Expert Systems & Prolog
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Prolog programming
Prolog programmingProlog programming
Prolog programming
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 
Predicate Calculus
Predicate CalculusPredicate Calculus
Predicate Calculus
 
Interestingand unusual
Interestingand unusualInterestingand unusual
Interestingand unusual
 
Akashdeepsinghjandu13
Akashdeepsinghjandu13Akashdeepsinghjandu13
Akashdeepsinghjandu13
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
Computer Graphics Project Development Help with OpenGL computer graphics proj...
Computer Graphics Project Development Help with OpenGL computer graphics proj...Computer Graphics Project Development Help with OpenGL computer graphics proj...
Computer Graphics Project Development Help with OpenGL computer graphics proj...
 
Introduction to Prolog
Introduction to PrologIntroduction to Prolog
Introduction to Prolog
 
تشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائيتشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائي
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
Leveraging Symfony2 Forms
Leveraging Symfony2 FormsLeveraging Symfony2 Forms
Leveraging Symfony2 Forms
 
Advanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems SolutionAdvanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems Solution
 
Computer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithmComputer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithm
 

Similar to WLPE12

Intelligent Methods in Models of Text Information Retrieval: Implications for...
Intelligent Methods in Models of Text Information Retrieval: Implications for...Intelligent Methods in Models of Text Information Retrieval: Implications for...
Intelligent Methods in Models of Text Information Retrieval: Implications for...
inscit2006
 
Prolog as-meta-lang-pres
Prolog as-meta-lang-presProlog as-meta-lang-pres
Prolog as-meta-lang-pres
Guy Wiener
 
Msr11.ppt
Msr11.pptMsr11.ppt
Efficient Probabilistic Logic Programming for Biological Sequence Analysis
Efficient Probabilistic Logic Programming for Biological Sequence AnalysisEfficient Probabilistic Logic Programming for Biological Sequence Analysis
Efficient Probabilistic Logic Programming for Biological Sequence Analysis
Christian Have
 
Fuzzy modelling using sciFLT
Fuzzy modelling using sciFLTFuzzy modelling using sciFLT
Fuzzy modelling using sciFLT
Umang Shukla
 
Model-Based Diagnosis of Discrete Event Systems via Automatic Planning
Model-Based Diagnosis of Discrete Event Systems via Automatic PlanningModel-Based Diagnosis of Discrete Event Systems via Automatic Planning
Model-Based Diagnosis of Discrete Event Systems via Automatic Planning
LUCACERIANI1
 
Fuzzy Logic Ppt
Fuzzy Logic PptFuzzy Logic Ppt
Fuzzy Logic Pptrafi
 

Similar to WLPE12 (7)

Intelligent Methods in Models of Text Information Retrieval: Implications for...
Intelligent Methods in Models of Text Information Retrieval: Implications for...Intelligent Methods in Models of Text Information Retrieval: Implications for...
Intelligent Methods in Models of Text Information Retrieval: Implications for...
 
Prolog as-meta-lang-pres
Prolog as-meta-lang-presProlog as-meta-lang-pres
Prolog as-meta-lang-pres
 
Msr11.ppt
Msr11.pptMsr11.ppt
Msr11.ppt
 
Efficient Probabilistic Logic Programming for Biological Sequence Analysis
Efficient Probabilistic Logic Programming for Biological Sequence AnalysisEfficient Probabilistic Logic Programming for Biological Sequence Analysis
Efficient Probabilistic Logic Programming for Biological Sequence Analysis
 
Fuzzy modelling using sciFLT
Fuzzy modelling using sciFLTFuzzy modelling using sciFLT
Fuzzy modelling using sciFLT
 
Model-Based Diagnosis of Discrete Event Systems via Automatic Planning
Model-Based Diagnosis of Discrete Event Systems via Automatic PlanningModel-Based Diagnosis of Discrete Event Systems via Automatic Planning
Model-Based Diagnosis of Discrete Event Systems via Automatic Planning
 
Fuzzy Logic Ppt
Fuzzy Logic PptFuzzy Logic Ppt
Fuzzy Logic Ppt
 

Recently uploaded

UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

WLPE12

  • 1. Introduction Background Extensions Type Inference Implementation Results Conclusion . Implementation of a Gradual Polymorphic Type System with . Standard Subtyping for Prolog Spyros Hadjichristodoulou David S. Warren1 Stony Brook University Computer Science Department WLPE 2012 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 1 / 23
  • 2. Introduction Background Extensions Type Inference Implementation Results Conclusion Types in Prolog? Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 2 / 23
  • 3. Introduction Background Extensions Type Inference Implementation Results Conclusion Types in Prolog? . Theorem (Most Prolog Books) .. Prolog is an untyped language... . Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 2 / 23
  • 4. Introduction Background Extensions Type Inference Implementation Results Conclusion Types in Prolog? . Theorem (Most Prolog Books) .. Prolog is an untyped language... . Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 2 / 23
  • 5. Introduction Background Extensions Type Inference Implementation Results Conclusion Types in Prolog? . Theorem (Most Prolog Books) .. Prolog is an untyped language... . Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 2 / 23
  • 6. Introduction Background Extensions Type Inference Implementation Results Conclusion Previous works Mycroft-O’Keefe’s type system (DEC-10) Mercury, Visual Prolog Type inference by abstract interpretation (Barbuti,Giacobazzi - 1990s) Towards typed Prolog (Schrijvers, Santos Costa, Wielemaker, Demoen - 2009) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 3 / 23
  • 7. Introduction Background Extensions Type Inference Implementation Results Conclusion Previous works Mycroft-O’Keefe’s type system (DEC-10) Mercury, Visual Prolog Type inference by abstract interpretation (Barbuti,Giacobazzi - 1990s) Towards typed Prolog (Schrijvers, Santos Costa, Wielemaker, Demoen - 2009) Why do Prolog vendors still keep it type-free? Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 3 / 23
  • 8. Introduction Background Extensions Type Inference Implementation Results Conclusion Our vision A Gradual Polymorphic type system with Subtyping Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 4 / 23
  • 9. Introduction Background Extensions Type Inference Implementation Results Conclusion Our 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 David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 4 / 23
  • 10. Introduction Background Extensions Type Inference Implementation Results Conclusion The 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 David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 5 / 23
  • 11. Introduction Background Extensions Type Inference Implementation Results Conclusion The 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 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 5 / 23
  • 12. Introduction Background Extensions Type Inference Implementation Results Conclusion The 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 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 5 / 23
  • 13. Introduction Background Extensions Type Inference Implementation Results Conclusion The 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 signature Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 5 / 23
  • 14. Introduction Background Extensions Type Inference Implementation Results Conclusion Towards Typed Prolog (2009) Implementation of the Mycroft-O’Keefe type system For SWI-Prolog and YAProlog Type checking Interaction between typed and untyped code Typed Prolog vs untyped Prolog Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 6 / 23
  • 15. Introduction Background Extensions Type Inference Implementation Results Conclusion Type inference by abstract interpretation (1990s) A . bstract P . redicate A . bstraction R . epresentation fi .x Extension with type union Able to type metapredicates (univ/2) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 7 / 23
  • 16. Introduction Background Extensions Type Inference Implementation Results Conclusion ActionScript and Erlang ActionScript: Gradual type systems: mixing static and dynamic type checking User has control over portion of program statically checked Recently added type inference Erlang: Dialyzer tool for static analysis Gradually applied Dialyzer to Wrangler Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 8 / 23
  • 17. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (1) ⊤ integer float ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 9 / 23
  • 18. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (1) ⊤ c number t t t ) t ” integer float t t t t ” ) ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 9 / 23
  • 19. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (1) ⊤ c number t . t Example 2 t .. ) t ” foo(42). integer float . foo(4.2). t t t t ” ) ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 9 / 23
  • 20. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (1) ⊤ c number t . t Example 2 t .. ) t ” foo(integer). integer float . foo(float). t t t t ” ) ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 9 / 23
  • 21. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (1) ⊤ c number t . t Example 2 t .. ) t ” foo(number). integer float . t t t t ” ) ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 9 / 23
  • 22. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (2) ⊤ number atom t £ t £ ) t ” integer float £ £ t £ t £ t c£ ” t ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 10 / 23
  • 23. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (2) ⊤ c atomic t t ) t ” number atom t £ t £ ) t ” integer float £ £ t £ t £ t c£ ” t ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 10 / 23
  • 24. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (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 David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 10 / 23
  • 25. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (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 David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 10 / 23
  • 26. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (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 David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 10 / 23
  • 27. Introduction Background Extensions Type Inference Implementation Results Conclusion Extensions (2) ⊤ c atomic t t . ) t ” Example 3 number atom .. t £ foo(atomic). t £ ) t ” integer float £ . £ t £ t £ t c£ ” t ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 10 / 23
  • 28. Introduction Background Extensions Type Inference Implementation Results Conclusion The struct type . lookup/3 .. . Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 11 / 23
  • 29. Introduction Background Extensions Type Inference Implementation Results Conclusion The struct type . lookup/3 .. :- type list(A) --- [] ; [A|list(A)]. . Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 11 / 23
  • 30. Introduction Background Extensions Type Inference Implementation Results Conclusion The struct type . lookup/3 .. :- type list(A) --- [] ; [A|list(A)]. lookup([], ,0). . lookup([X’=’Y|T],X,Y) :- atom(X),integer(Y),lookup(T, , ). Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 11 / 23
  • 31. Introduction Background Extensions Type Inference Implementation Results Conclusion The struct type . lookup/3 .. :- type list(A) --- [] ; [A|list(A)]. :- pred lookup(list(struct),atom,integer). lookup([], ,0). . lookup([X’=’Y|T],X,Y) :- atom(X),integer(Y),lookup(T, , ). Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 11 / 23
  • 32. Introduction Background Extensions Type Inference Implementation Results Conclusion The struct type . lookup/3 .. :- type list(A) --- [] ; [A|list(A)]. :- type pair(A,B) --- A (=) B. :- pred lookup(list(struct),atom,integer). lookup([], ,0). . lookup([X’=’Y|T],X,Y) :- atom(X),integer(Y),lookup(T, , ). Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 11 / 23
  • 33. Introduction Background Extensions Type Inference Implementation Results Conclusion The struct type . lookup/3 .. :- type list(A) --- [] ; [A|list(A)]. :- type pair(A,B) --- A (=) B. :- pred lookup(list(pair(atom,integer),atom,integer)). lookup([], ,0). . lookup([X’=’Y|T],X,Y) :- atom(X),integer(Y),lookup(T, , ). Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 11 / 23
  • 34. Introduction Background Extensions Type Inference Implementation Results Conclusion Subtyping relation ⊤   d   © ‚ d atomic struct t ¢ t ¢ ) t ” ¢ number atom ¢ t ¢ t ¢ ) t ” ¢ integer float ¢  t ¢  t  ¢  ” t c ¢  ~  ¢ ⊥ Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 12 / 23
  • 35. Introduction Background Extensions Type Inference Implementation Results Conclusion The cult of the bound variable Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 13 / 23
  • 36. Introduction Background Extensions Type Inference Implementation Results Conclusion The cult of the bound variable Why even bother doing type inference? Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 13 / 23
  • 37. Introduction Background Extensions Type Inference Implementation Results Conclusion The cult of the bound variable Why even bother doing type inference? Similar method to “Type inference by abstract interpretation” Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 13 / 23
  • 38. Introduction Background Extensions Type Inference Implementation Results Conclusion The cult of the bound variable Why even bother doing type inference? Similar method to “Type inference by abstract interpretation” Infrastructure taken by “Towards Typed Prolog” Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 13 / 23
  • 39. Introduction Background Extensions Type Inference Implementation Results Conclusion The cult of the bound variable Why even bother doing type inference? Similar method to “Type inference by abstract interpretation” Infrastructure taken by “Towards Typed Prolog” Type variables vs Prolog variables Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 13 / 23
  • 40. Introduction Background Extensions Type Inference Implementation Results Conclusion The cult of the bound variable Why even bother doing type inference? Similar method to “Type inference by abstract interpretation” Infrastructure taken by “Towards Typed Prolog” Type variables vs Prolog variables A . 2 T .2 . . A . 1 T .1 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 13 / 23
  • 41. Introduction Background Extensions Type Inference Implementation Results Conclusion The idea . General Idea .. repeat For a predicate H, let {H1 , . . . , Hn } be the heads of the clauses that define it for all Hi ∈ {H1 , . . . , Hn } do Let Hi : −Bi be the respective clause of H for all B ∈ Bi do Find the type of B and accumulate variable-type bindings for the entire clause end for The new type for H is the intersection of the types found for each Hi end for . until No change is made to the inferred type for H Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 14 / 23
  • 42. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Type Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 43. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 1 Type Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 44. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 1 Type Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 45. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 1 member(A,list(A)) Type Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 46. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 1 member(A,list(A)) Type Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 47. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 1 member(A,list(A)) member(B,list(C)) Type Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 48. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 1 member(A,list(A)) member(B,list(C)) Type member(A,list(A)) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 49. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 1 Type member(A,list(A)) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 50. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 2 Type member(A,list(A)) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 51. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 2 Type member(A,list(A)) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 52. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 2 member(A,list(A)) Type member(A,list(A)) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 53. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 2 member(A,list(A)) Type member(A,list(A)) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 54. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 2 member(A,list(A)) member(B,list(B)) Type member(A,list(A)) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 55. Introduction Background Extensions Type Inference Implementation Results Conclusion An example . Example 4: member/2 .. :- type list(A) --- [] ; [A|list(A)]. member(X,[X| ]). . member(X,[ |T]) :- member(X,T). Iteration 2 member(A,list(A)) member(B,list(B)) Type member(B,list(B)) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 15 / 23
  • 56. Introduction Background Extensions Type Inference Implementation Results Conclusion Overview Compile Load Execute XSB Disk .P Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 16 / 23
  • 57. Introduction Background Extensions Type Inference Implementation Results Conclusion Overview User 1 c Compile Load Execute XSB Disk .P Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 16 / 23
  • 58. Introduction Background Extensions Type Inference Implementation Results Conclusion Overview User 1 c Compile Load Execute XSB Disk Type 2 Analysis ' .P XSB Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 16 / 23
  • 59. Introduction Background Extensions Type Inference Implementation Results Conclusion Overview User 1 c Compile Load Execute XSB T 3 Disk Type 2 Analysis ' .P XSB Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 16 / 23
  • 60. Introduction Background Extensions Type Inference Implementation Results Conclusion Overview User 1 c Compile Load Execute XSB T 4 3 Disk Type 2 Analysis ' .P XSB E .xwam Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 16 / 23
  • 61. Introduction Background Extensions Type Inference Implementation Results Conclusion Overview User 1 c Compile Load Execute XSB T 4 T 3 Disk Type 2 Analysis ' .P 5 XSB E .xwam Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 16 / 23
  • 62. Introduction Background Extensions Type Inference Implementation Results Conclusion Overview User 1 c Compile Load 6 E Execute XSB T 4 T 3 Disk Type 2 Analysis ' .P 5 XSB E .xwam Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 16 / 23
  • 63. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 17 / 23
  • 64. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f . (21). Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 17 / 23
  • 65. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(21). f(42). . Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 17 / 23
  • 66. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(21). f(42). f(84). . Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 17 / 23
  • 67. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling with Answer Subsumption Answer Subsumption Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 18 / 23
  • 68. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling with Answer Subsumption . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. Answer Subsumption Lattice operation: max/3 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 18 / 23
  • 69. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling with Answer Subsumption . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(21). . Answer Subsumption Lattice operation: max/3 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 18 / 23
  • 70. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling with Answer Subsumption . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(42). . Answer Subsumption Lattice operation: max/3 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 18 / 23
  • 71. Introduction Background Extensions Type Inference Implementation Results Conclusion Tabling with Answer Subsumption . |?- f(X). .. f(21). f(42). f(84). . . Global Table .. f(84). . Answer Subsumption Lattice operation: max/3 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 18 / 23
  • 72. Introduction Background Extensions Type Inference Implementation Results Conclusion The code (1) . Type inference: tabling with answer subsumption .. type inference n(Head,Type) :- copy term1(Head,Type), numbervars(Head,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 David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 19 / 23
  • 73. Introduction Background Extensions Type Inference Implementation Results Conclusion The code (2) . Lattice operation: unification .. type unify(X,Y,X1) :- unnumbervars(X,0,X1), unnumbervars(Y,0,Y1), X1 = Y1, . numbervars(X1,0, ). Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 20 / 23
  • 74. Introduction Background Extensions Type Inference Implementation Results Conclusion Results (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.105 Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 21 / 23
  • 75. Introduction Background Extensions Type Inference Implementation Results Conclusion What’s next? D . eclaration Free T . . est/Debug M . odules M . etapredicates Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 22 / 23
  • 76. Introduction Background Extensions Type Inference Implementation Results Conclusion Thanks for your attention :-) Spyros Hadjichristodoulou David S. Warren Impl. of a Gradual Pol. Type System with St. Subtyping for Prolog 23 / 23