Treatment of Types in an Implementation of λProlog Organized around Higher-Order Pattern Unification Xiaochu Qi Department of Computer Science and Engineering.

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
First Order Logic Logic is a mathematical attempt to formalize the way we think. First-order predicate calculus was created in an attempt to mechanize.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
SLD-resolution Introduction Most general unifiers SLD-resolution
10 October 2006 Foundations of Logic and Constraint Programming 1 Unification ­An overview Need for Unification Ranked alfabeths and terms. Substitutions.
Type Analysis and Typed Compilation Stephanie Weirich Cornell University.
Letrec fact(n) = if zero?(n) then 1 else *(n, (fact sub1(n))) 4.4 Type Inference Type declarations aren't always necessary. In our toy typed language,
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
Standard Logical Equivalences
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
First Order Logic Resolution
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Type Checking.
Compiler Principle and Technology Prof. Dongming LU Mar. 28th, 2014.
1 Applied Computer Science II Resolution in FOL Luc De Raedt.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Catriel Beeri Pls/Winter 2004/05 types 65  A type-checking algorithm The task: (since we start with empty H, why is the goal not just E?) The rule set.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Type Inference David Walker CS 510, Fall Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs.
Implicit Typing in Lambda Logic Copyright, 2005 Michael Beeson ESHOL Workshop LPAR-12 Jamaica, 2005.
1 A Short Introduction to (Object-Oriented) Type Systems Kris De Volder.
Type Inference: CIS Seminar, 11/3/2009 Type inference: Inside the Type Checker. A presentation by: Daniel Tuck.
Inheritance and Polymorphism CS351 – Programming Paradigms.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Formal Models of Computation Part II The Logic Model
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Conjunctive normal form: any formula of the predicate calculus can be transformed into a conjunctive normal form. Def. A formula is said to be in conjunctive.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L06-1 September 26, 2006http:// Type Inference September.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Chapter 1 Introduction Major Data Structures in Compiler
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
Predicate Abstraction. Abstract state space exploration Method: (1) start in the abstract initial state (2) use to compute reachable states (invariants)
Principles of programming languages 6: Types Isao Sasano Department of Information Science and Engineering.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
1 Reasoning with Infinite stable models Piero A. Bonatti presented by Axel Polleres (IJCAI 2001,
CS 152: Programming Language Paradigms March 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
C H A P T E R T H R E E Type Systems and Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
COMP 412, FALL Type Systems II C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
1 First Order Logic CS 171/271 (Chapter 8) Some text and images in these slides were drawn from Russel & Norvig’s published material.
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
Cs776(Prasad)L6sml971 SML-97 Specifics SML/NJ 110.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Polymorphism in Methods
Principles of programming languages 12: Functional programming
ML: a quasi-functional language with strong typing
Principles of programming languages 8: Types
Prolog Concepts.
Object Oriented Programming
Abstract Classes AKEEL AHMED.
Announcements Quiz 5 HW6 due October 23
Prolog Concepts.
Prolog Concepts.
Python fundamental.
Presentation transcript:

Treatment of Types in an Implementation of λProlog Organized around Higher-Order Pattern Unification Xiaochu Qi Department of Computer Science and Engineering University of Minnesota

Types in Logic Programming Languages descriptive notion: typed Prolog parametric polymorphism type nil (list A). type :: A -> (list A) -> (list A). type append (list A) -> (list A) -> (list A) -> o.

Types in Logic Programming Languages prescriptive notion: λProlog mixed usage of parametric and ad hoc polymorphism type print_int int -> o. type print_str string -> o. type print A -> o. print X :- print_int X. print X :- print_str X. print X.

The Nature of Polymorphism in λProlog a polymorphic version of the simply typed λ-calculus atomic types: including type variables the intuitive meaning of a term t :σ {t :σ ’ |σ ’ is a closed instance of σ }

The Roles of Types in λProlog a strongly typed language type declarations for constants inferring types for all subterms prevent run-time failures well-typedness: compile time type-checking participate in unification

∀ :: ∀ nil ∀ append  F ∀ c A Prefix of Mixed Quantifiers ?- (  F)(append (c::nil) nil (F c)). universal variable existential variable constant ?- (  F) ∀ c(append (c::nil) nil (F c)). ∀ c ∀ :: ∀ nil ∀ append  F

Types of Constants and Variables The occurrences of a constant can have different types. The occurrences of a universal or existential variable must always have identical types. type nil (list A). type :: A -> (list A) -> (list A). (1 :: nil) (“a” :: nil) (1 :int :: :int->(list int)->(list int) nil :(list int) ) (“a” :string :: :string->(list string)->(list string) nil :(list string) )

Higher-Order Unification determine the identity of constants decide the structures of unifiers Types are associated with every variable and constant.

Higher-Order Pattern Unification determine the identity of constants a universal or existential variable: always has identical types in different occurrences can have a polymorphic type, which could be specialized during unification

Typed Higher-Order Pattern Unification processing terms in a top-down manner iterative usage of: term simplification phase: simply non-existential variable head applications binding phase decide the structure of bindings for existential variables invariant: Terms to be unified always have identical types.

Typed Higher-Order Pattern Unification term simplification phase: constant heads: examine (specialize) the types of these constants others: already have identical types binding phase: identical types of the entire terms identical types of relevant variables no comparison on constants No need for type examination

∀ g  F ∀ c  X ∀ a type g A -> B. τ(c)= A->B τ(a)= C τ(X)= C->A τ(F)= (A->B)->int D (c :A->B (X :C->A a :C )), (g :int->D (F :(A->B)->int c :A->B ))> (r-r): { } int (X :C->A a :C ), F :(A->int)->int c :A->int > (r-f): { } ∀ g  H  F ∀ c  X ∀ a A a :C, H :(A->int)->A c :A->int > (f-f): {, }

∀ 1 ∀ ”a” ∀ f  X  Y ∀ c type f A -> B -> C. τ(c)= A->B τ(X)= A τ(Y)= B string->B->C X :A “a” :string (c :A->B X :A ), f :int->A->B->C 1 :int Y :A (c :A->B Y :A )>

Maintain Types with Constants only associating types with constants Exp1 : ∀ g  F ∀ c  X ∀ a D (c :A->B (X :C->A a :C )), (g :int->D (F :(A->B)->int c :A->B ))> D (c (X a)), (g :int->D (F c))> Exp2 : ∀ 1 ∀ ”a” ∀ f  X  Y string->B->C X :A “a” :string (c :A->B X :A ), f :int->A->B->C 1 :int Y :A (c :A->B Y :A )> string->B->C X “a” (c X), f :int->A->B->C 1 Y (c Y)>

Maintain instances of type variables well-typedness with respect to type declarations compile time type-checking instances of type variables run time type-checking (:: :[list A] (:: :[A] X nil :[A] ) nil: [list A] ) Exp1: D (c (X a)), (g :int->D (F c))> (:: (:: X nil) nil) (:: :(list A)->(list (list A))->(list (list A) ) (:: :A->(list A)->(list A) X nil :(list A) ) nil :(list (list A)) )

Type Preservation Type variables occurring in target types have been checked at a upper level. Constant function symbols: type variables not occurring in target types Non-function constants: no need to maintain types type :: A -> (list A) -> (list A). type nil (list A). (:: :[list A] (:: :[A] X nil :[A] ) nil :[list A] ) (:: (:: X nil) nil) type g (A -> B) -> A. type a int -> B. (:: :[int] (g :[int,B] a :[int,B] ) nil :[int] ) (:: (g [B] a) nil)

Teyjus: id A (:: A X L) (:: A X K) :- id A L K. Type Processing Effort in Compiled Unification type id (list A) -> (list A) -> o. id nil nil. id (X::L) (X::K) :- id L K. ?- id (1::nil) T. Our scheme: id A (:: X L) (:: X K) :- id A L K. Teyjus: ?- id int (:: int 1 nil) T. Our scheme: ?- id int (:: 1 nil) T.

bind (T, (:: A S2 K)); bind (A, int); bind (S2, X); (write mode) (read mode) bind (T, (:: S2 K)); Type Processing in Compiled Unification over bind (A, int); bind (X, 1); bind (L, nil);

Type generality Typed Prolog : type p σ 1 -> … -> σ n -> o. p t 1 … t n :- b 1, …, b m. τ ( t 1 )= σ 1, …, τ ( t n )= σ n Every sub-term of t i is type preserving. Only type general and preserving programs are well-typed. λProlog : mixed usage of parametric and ad hoc polymorphism

Type generality in λProlog type print A -> o. type print_int int -> o. type print_str string -> o. print X :- print_int X. print X :- print_string X. print X. type generality and preservation property should hold on every clause head defining a predicate.

Type generality in λProlog type foo A -> o. foo X :- print X. type variables of the clause head should not be used in body goals.

Conclusion Type examination is necessary in higher-order pattern unification. Reduce type association and run-time type examination constant function symbols separate static and dynamic information take advantage of the type preservation property

Future work prove the correctness of the typed higher-order pattern unification scheme taking advantage of the type generality property making usage in implementations