1 Scrapping “Scrap Your Nameplate” Michael D. Adams.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Let should not be generalized Dimitrios Vytiniotis, Simon Peyton Jones Microsoft Research, Cambridge TLDI’1 0, Madrid, January 2010 Tom Schrijvers K.U.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Semantics Static semantics Dynamic semantics attribute grammars
Exercise 1 Generics and Assignments. Language with Generics and Lots of Type Annotations Simple language with this syntax types:T ::= Int | Bool | T =>
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Simplified Gated Assignment Surinder Jain Supervisor : Bernhard Scholz Assignment 3 – INFO5993.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
GATEKEEPER MOSTLY STATIC ENFORCEMENT OF SECURITY AND RELIABILITY PROPERTIES FOR JAVASCRIPT CODE Salvatore Guarnieri & Benjamin Livshits Presented by Michael.
Extending Pattern Directed Inference Systems Algo & Data 2.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Katz Formal Specifications Larch 1 Algebraic Specification and Larch Formal Specifications of Complex Systems Shmuel Katz The Technion.
Syntax With Binders COS 441 Princeton University Fall 2004.
Solve Multi-step Equations (var. both sides) Students will solve multi-step equations with variables on both sides using distributive property, combining.
Building SSA Form, III 1COMP 512, Rice University This lecture presents the problems inherent in out- of-SSA translation and some ways to solve them. Copyright.
Implementing a Dependently Typed λ -Calculus Ali Assaf Abbie Desrosiers Alexandre Tomberg.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Higher-Order Encodings in Intensional Type Theory Edwin Westbrook Rice University.
Simon Peyton Jones, Stephanie Weirich, Richard Eisenberg, Dimitrios Vytiniotis Microsoft Research University of Pennsylvania April 2016.
1 Interactive Computer Theorem Proving CS294-9 October 19, 2006 Adam Chlipala UC Berkeley Lecture 9: Beyond Primitive Recursion.
1 Interactive Computer Theorem Proving CS294-9 September 7, 2006 Adam Chlipala UC Berkeley Lecture 3: Data structures and Induction.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
CS5205: Foundation in Programming Languages Type Reconstruction
Generic Programming and Proving for Programming Language Metatheory
Lecture 11: Proof by Reflection
Type Checking and Type Inference
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Introduction Edited by Enas Naffar using the following textbooks: - A concise introduction to Software Engineering - Software Engineering for students-
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Instructor: Laura Kallmeyer
Hans Bodlaender, Marek Cygan and Stefan Kratsch
CS 4450: Principles of Programming Languages
Relational Algebra Chapter 4 1.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Atomic Operations in Hardware
Algorithm Analysis CSE 2011 Winter September 2018.
Repeating code We could repeat code we need more than once: i = 1 print (i) i += 1 print (i) #… stop when i == 9 But each line means an extra line we might.
Introduction Edited by Enas Naffar using the following textbooks: - A concise introduction to Software Engineering - Software Engineering for students-
Main Points of Haskell Functional programming Laziness
PROGRAMMING IN HASKELL
Stateful Manifest Contracts
Programming Languages and Compilers (CS 421)
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
CSE 341: Programming Langs
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Introduction to Computer Programming
Relational Algebra 1.
Microsoft Research University of Pennsylvania
Lecture 09:Software Testing
CSCE 411 Design and Analysis of Algorithms
Relational Algebra Chapter 4 1.
Objective of This Course
Do Now 1) t + 3 = – 2 2) 18 – 4v = 42.
Closure Representations in Higher-Order Programming Languages
PROGRAMMING IN HASKELL
Closure Closure binds a first-class function and a lexical environment together This is a complex topic, so we will build up our understanding of it we.
Coding Concepts (Basics)
Compiler Code Optimizations
Binding Times Binding is an association between two things Examples:
Debugging EECS150 Fall Lab Lecture #4 Sarah Swisher
Trace-based Just-in-Time Type Specialization for Dynamic Languages
CS 188: Artificial Intelligence Fall 2008
Debugging EECS150 Fall Lab Lecture #4 Sarah Swisher
C. M. Overstreet Old Dominion University Spring 2006
Presentation made by Steponas Šipaila
Theorems on Redundancy Identification
Optimization.
C. M. Overstreet Old Dominion University Fall 2007
Presentation transcript:

1 Scrapping “Scrap Your Nameplate” Michael D. Adams

2 Introduction “Scrap Your Nameplate” by James Cheney (author of αProlog) “Scrap Your Boilerplate” by Simon Peyton Jones et al. Nominal Logic αKanren Nominal Programing

3 Introduction SYN fails at any synergy between αL and SYB SYN is αProgramming rather than αLogic SYN doesn't match the theory (but it could)

4 Overview What SYN does User Level Behind the Scenes Examples YAαP

5 Overview How to improve SYN Fixing the logic to match the theory Fixing the “fixed” logic to be efficient Misc Solve the AST restrictions How Haskell/Scheme should be changed

6 SYN: User Level Types: Name, a \\\ b class Nom t where swap :: Name -> Name -> t -> t fresh :: Name -> t -> Bool aeq :: t -> t -> Bool class Subst class FreeVars

7 SYN: Thesis “Writing 'nameplate' code is boring” (Only issue in a language with user defined types) Use SYB to implement SYN One CAS to rule them all

8 What is SYB? SYB writes the boring parts functions over tree shaped data types for you Best seen with example

9 Write “getUsedVars” data Type = VarTy Name | FnTy Type Type | AllTy (Name \\\ Type) data Term = Var Name | App Term Term | Lam Type (Name \\\ Term) | TyLam (Name \\\ Term) | TyApp Term Type

10 What is SYB? Write all functions in terms of gfoldl gfoldl is automatically generated for all data types class (Typeable a) => Data a where gfoldl :: (forall a b. (Data a) => c (a -> b) -> a -> c b) -> (forall g. g -> c g) -> a -> c a

11 SYB → SYN Scrap Your Boilerplate getUsedVars Scrap Your Nameplate getFreeVars SYN requires: All binders use (Name \\\ a) Info about variables

12 SYB → SYN instance HasVar Type where is_var (VarTy x) = Just x is_var _ = Nothing var x = VarTy x instance HasVar Term where is_var (Var x) = Just x is_var _ = Nothing var x = Var x

13 SYB → SYN You write HasVar SYB writes gfoldl SYN gives you Nom, Subst, FreeVars for FREE!

14 So what is wrong?

15 So what is wrong? Consider this function dirty (Lam ty1 (x1 \\\ (Lam ty2 (x2 \\\ body)))) = (Lam ty1 (x1 \\\ (Lam ty2 (x2 \\\ (App (Var x1) body))))) What if x1 = x2?

16 SYN Solution unAbs :: (FreshMonad m) => (a \\\ t) -> m (a, t) unAbs (a \\\ t) = do a' <- freshen a return (a', swap a a' t)

17 Why is the solution wrong? R: But that ignores the nominal logic side conditions! M: What side conditions? R: Functions should only be able to deconstruct (a \\\ t) if “a” remains fresh in its output M: Example?

18 Why is the solution wrong? R: dirtier (Lam ty1 rest) = do (x, body) <- unAbs rest return body M: Why is that a problem? R: This breaks observational equivalance

19 Why is the solution wrong? M: How? R: do t1 = Lam ty (a \\\ Var a) t2 <- dirtier t1 t3 <- dirtier t1 return (t2 == t3, t2 `aeq` t3)

20 How do we fix the solution? liftAlpha :: ((a, t1) -> m t2) -> ((a \\\ t1) -> m t2) liftAlpha f (a \\\ t1) = do a' <- freshen a t2 <- f (a, swap a a' t1) if fresh a t2 then return t2 else throwError

21 Can these checks be fast? Static checks See Rice's Theorem Dynamic checks O(size(t)) or maybe not... Or maybe nominal theory is wrong R: No it isn't!

22 Can these checks be fast? (swap a a' t1) causes O(size(t)) cost Eliminate by introducing suspended swaps Suspended swaps “pushed-down” on demand Combine neighboring swaps (swap a b (swap b c t)) → (swap a c t) only if swaps generated by liftAlpha because “a” and “b” are gensym and thus are fresh in “t” Constant overhead cost

23 Can these checks be fast? (fresh a' t2) also causes O(size(t)) cost (fresh a' t1) stops when it sees (swap a' a (a \\\ t2)) = (a' \\\ t2) (fresh a' t1) will not stop when it sees (swap a' a (... (Var a))) Problem!

24 Can these checks be fast? (fresh a' t2) also causes O(size(t)) cost (fresh a t2) implies (fresh a' (swap a' a t2)) Keep cached free variable info on each term Ugh! But what else can we do?

25 Misc Improvements Parameterize over Binders Like HasVar is used to parameterize over variables class Bind a t where is_bind :: t -> Maybe (a, t) Suspended swaps behave a lot like thunks Add user defined thunks to Haskell? Thunk operations: Construct, Force, Combine Must avoid “isThunk” predicate

26 Conclusion SYN saves you from writing “nameplate” But doesn't ensure that your functions are nominally correct Dynamic checks for nominal correctness asymptotically expensive

27 Conclusion Optimizations might bring expense down to constant factor Might → No implementation yet, only design But they may require heavy weight meta-data on each value to be kept Are they worth it? Discuss