Structure. Background. them to their higher order equivalents. functionals in Standard ML source code and converts

Similar documents
Outline. A recursive function follows the structure of inductively-defined data.

Declarative Computation Model. Conditional. Case statement. Procedure values (2) Procedure values. Sequential declarative computation model

Compiling Techniques

Interoperation for Lazy and Eager Evaluation

Principles of Program Analysis: A Sampler of Approaches

CFLs and Regular Languages. CFLs and Regular Languages. CFLs and Regular Languages. Will show that all Regular Languages are CFLs. Union.

Unification and occur check. The programming language Prolog

CSC 4181Compiler Construction. Context-Free Grammars Using grammars in parsers. Parsing Process. Context-Free Grammar

Programming Languages and Types

6.001 Recitation 22: Streams

Notes on Inductive Sets and Induction

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

Nunchaku: Flexible Model Finding for Higher-Order Logic

Propositional Logic: Part II - Syntax & Proofs 0-0

Outline. Overview. Syntax Semantics. Introduction Hilbert Calculus Natural Deduction. 1 Introduction. 2 Language: Syntax and Semantics

Deductive Verification

Extending the Lambda Calculus: An Eager Functional Language

Harvard CS 121 and CSCI E-207 Lecture 9: Regular Languages Wrap-Up, Context-Free Grammars

THEORY OF COMPILATION

Thesis Title Second Line if Necessary

Abstract parsing: static analysis of dynamically generated string output using LR-parsing technology

Programming Languages and Types

Syntax Analysis Part I. Position of a Parser in the Compiler Model. The Parser. Chapter 4

Maschinelle Sprachverarbeitung

Maschinelle Sprachverarbeitung

A uniform programming language for implementing XML standards

Lambda Calculus! Gunnar Gotshalks! LC-1

Functional Big-step Semantics

Formal Methods Lecture 8. (B. Pierce's slides for the book Types and Programming Languages )

Programming Language Concepts, CS2104 Lecture 3

Declarative Programming for Agent Applications

CVO103: Programming Languages. Lecture 2 Inductive Definitions (2)

Bottom-Up Syntax Analysis

Order Sorted Algebra. Japan Advanced Institute of Science and Technology. March 8, 2008

Foundations of Programming Languages and Software Engineering

A Functional Language for Hyperstreaming XSLT

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus

Introduction to (Logic and Functional) Programming

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC)

A Modular Rewriting Semantics for CML

Lecture 4. Algebra. Section 1:. Signature, algebra in a signature. Isomorphisms, homomorphisms, congruences and quotient algebras.

Syntax Analysis Part I

Syntax Analysis Part I

The Life Cycle of Grammarware. CWI Scientific Meeting Vadim Zaytsev, SWAT, CWI 2012

Designing and Evaluating Generic Ontologies

Design of Embedded Systems: Models, Validation and Synthesis (EE 249) Lecture 9

SEMANTICS OF PROGRAMMING LANGUAGES Course Notes MC 308

The Complexity of First-Order Extensible Dependency Grammar

Principles of Program Analysis: Control Flow Analysis

Predicate Logic - Introduction

Lecture 12: Core State Machines II

Bringing machine learning & compositional semantics together: central concepts

CS1021. Why logic? Logic about inference or argument. Start from assumptions or axioms. Make deductions according to rules of reasoning.

The Formal Architecture of. Lexical-Functional Grammar. Ronald M. Kaplan and Mary Dalrymple

Lecture 11 Context-Free Languages

An Introduction to Z3

CSCI 1590 Intro to Computational Complexity

Integer Clocks and Local Time Scales

Compiling Techniques

Syntactic Analysis. Top-Down Parsing

A DOP Model for LFG. Rens Bod and Ronald Kaplan. Kathrin Spreyer Data-Oriented Parsing, 14 June 2005

Context-Free Grammars (and Languages) Lecture 7

CSCI 490 problem set 6

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Chapter 2: Basic Notions of Predicate Logic

Theorem Proving beyond Deduction

Formalising the Completeness Theorem of Classical Propositional Logic in Agda (Proof Pearl)

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

Lectures on The Lambda Calculus (I)

Parsing -3. A View During TD Parsing

Introduction to ANTLR (ANother Tool for Language Recognition)

Static Program Analysis

Rigorous Software Development CSCI-GA

Meta-programming & you

Safety Analysis versus Type Inference

Movement-Generalized Minimalist Grammars

Context-Free Grammars and Languages. We have seen that many languages cannot be regular. Thus we need to consider larger classes of langs.

TALP at GeoQuery 2007: Linguistic and Geographical Analysis for Query Parsing

Parsing Beyond Context-Free Grammars: Tree Adjoining Grammars

Representing structured relational data in Euclidean vector spaces. Tony Plate

COSE312: Compilers. Lecture 2 Lexical Analysis (1)

Predicate Logic. Xinyu Feng 11/20/2013. University of Science and Technology of China (USTC)

An Abstract Interpretation Framework for Semantics and Diagnosis of Lazy Functional-Logic Languages

Higher Order Containers

First-Order Logic. Chapter Overview Syntax

Annotation tasks and solutions in CLARIN-PL

Compiling Techniques

Limitations of OCAML records

Data Analysis 1 INTRODUCTION

Well Founded Relations and Recursion

UNIT II REGULAR LANGUAGES

Notes from Yesterday s Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons.

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing

CS156: The Calculus of Computation

Syntax Directed Transla1on

Mixing Finite Success and Finite Failure. Automated Prover

INF5110 Compiler Construction

Depending on equations

A Deterministic Logical Semantics for Esterel

CONTEXT FREE GRAMMAR AND

Transcription:

Introduction 3 Background functionals factor out common behaviour map applies a function to every element of a list fun map [ ] = [ ] map f ( x : : xs ) = f x : : map f xs filter keeps only those elements of a list for which a predicate holds fun f i l t e r [ ] = [ ] f i l t e r pred ( x : : xs ) = i f pred x then x : : f i l t e r pred xs e l s e f i l t e r pred xs ; 4 Developing a program that detects possible uses of functionals in Standard ML source code and converts them to their higher order equivalents Philipp Mayerhofer March 7, 2003 1 Structure 1. Introduction 2. Problem analysis 3. Design and implementation 4. Conclusion 2

Aim Program detects possible uses of the functionals map and filter in Standard ML source code and converts them to their higher order equivalents Example: Notation possible use of map is expressible by a function fun s q u a r e [ ] = [ ] s q u a r e ( x : : xs ) = ( x x ) : : s q u a r e xs higher order equivalent v a l s q u a r e = map ( fn x = x x ) 5 Motivation educational software engineering optimisation 6., if Definition 1 A function, denoted is h-expressible by a function, if. Definition 2 A function, denoted is a higher order equivalent of a function Definition 3 An expression if. 7 Notation Example fun i n c l [ ] = [ ] i n c l ( x : : xs ) = ( x + 1 ) : : i n c l xs ; x + 1 ) ; v a l i n c l 2 = map ( fn x = incl is expressible by map map (fn x => x + 1) incl incl is h-expressible by map higher order equivalent of incl. map map incl 8

Templates fun f... [ ]... = [ ] f... ( x : : xs )... = some o p e r a t i o n : : f xs Problems: more than one way of expressing same functionality fun f... l... = i f l = [ ] then [ ] e l s e some o p e r a t i o n : : f ( t l l ) need meta variables for some operation 11 Problematic language constructs Pattern matching fun f1 [ ] = [ ] f1 ( x : : xs ) = ( x + 1 ) : : f1 xs ; fun f2 l = case l of [ ] = ( x : : xs ) = [ ] ( x + 1 ) : : f2 xs ; ( Does n o t compile w i t h o u t warning ) fun f3 l = i f ( l = [ ] ) then [ ] e l s e l e t v a l ( x : : xs ) = l in ( x + 1 ) : : f3 xs end ; 12 Problem analysis 9 Determining expressibility cf. matching fingerprints (a) Original fingerprint (b) Skeletal image define templates for structure of functionals match functions to templates to determine expressibility 10

Problematic language constructs Pattern matching (cont.) Normal form: convert to set of conditions and assignments define two meta-functions constr returns the constructor tag of a given type field of a given type field n returns the Example: function on previous slide converted to fun f l = i f ( c o n s t r l = [ ] ) then [ ] e l s e l e t v a l x = f i e l d 1 l v a l xs = f i e l d 2 l in ( x + 1 ) : : f xs end ; 13 Problematic language constructs Multiple arguments tuples vs. curried arguments fun f1 ( [ ], ) = [ ] f1 ( x : : xs, n ) = ( x+n ) : : f1 ( xs, n ) ; fun f2 [ ] = [ ] f2 ( x : : xs ) n = ( x+n ) : : f2 xs n ; tuples = single entity that give effect of multiple arguments restrict templates to curried arguments 14 Problematic language constructs Infix operators i n f i x d i v i d e s ; fun x d i v i d e s y = ( y mod x ) = 0 ; syntactic sugar for functions with two arguments 6 d i v i d e s 3 in non infix form op can apply op d i v i d e s ( 6, 3 ) normal form converts infix to non infix form op 15 Design and implementation 16

Implementation approach Working subset approach: 1. choose subset of Standard ML 2. implement program for the subset 3. gradually extend the subset 19 Conclusion 20 Architecture Input Lexical analysis token stream Parsing abstract syntax tree Normalisation normalised syntax tree Unification Output 17 Architecture (cont.) Unification stage: develop generic unification package data types for first order language terms unification algorithm for the data types divide unification stage into 2 stages: normalised syntax tree Convert to a first order language first order language Unify with templates (function, replacement) pairs 18

Summary introduced notation expressibility, h-expressibility, higher order equivalence showed how to determine expressibility cf. matching fingerprints unification with templates normal forms for pattern matching, infix operators explained architecture and implementation approach working subset approach analysed achievements and further work 23 Additional slides 24 Achievements fun double l = i f l = [ ] then [ ] e l s e ( ( hd l ) 2 ) : : double ( t l l ) ; fun double l = map ( fn x = ( op ( ( x, 2 ) ) ) ) l ; working program for subset of SML notation generic unification package 21 Further work extend subset improve generic unification package syntax for templates fun f... l... = i f ( l = [ ] ) then [ ] e l s e EXPR : : f ( t l l ) 22

Unification algorithm does not occur in such that then 1: disagreement set of 2: if then 3: return 4: else if variable term 5: for all do 6: 7: 8: goto step 1 9: else 10: return not unifiable 25 Algorithm 1: /* is an input source file */ 2: parse 3: normalise 4: set of function definitions in 5: templates of map filter 6: for all do 7: for all do 8: if unifies with then 9: convert to its higher order equivalent Initial subset minimal features to express functionals includes constants + tuples conditional expressions (if... then... else) boolean expressions (andalso, orelse) 26 excludes pattern matching infix operators nested expressions (let... in... end) exceptions entire module language 27