Download presentation
Presentation is loading. Please wait.
Published byMartina Bryan Modified over 8 years ago
1
Ur: Statically-Typed Metaprogramming with Type-Level Record Computation Adam Chlipala PLDI 2010
2
2 Programmer Effort Strength of Guarantee Verification Types Web Applications Operating Systems Compilers Runtime systems.... Dependent Types Type-Level Computation Ur/Web, a domain-specific language for metaprogramming Web applications
3
3 Object-Relational Mapping SQL Table Schema Metaprogram Object-Oriented Interface ● Add row ● Modify row ● Search ●...
4
4 Automatic Admin Interface SQL Table Schema IdABCD Metaprogram
5
5 In-Browser Spreadsheet
6
6 Ad-Hoc Code Generation? SQL Table Schema IdABCD script/generate scaffold T Id:int A:string B:float C:string D:int Metaprogra m app models post.rb views posts index.html.erb show.html.erb config routes.rb.... Edit some source files to customize.... Now change the database schema....
7
7 Run-Time Reflection? SQL Table Schema IdABCD Library uses reflection to behave differently based on object metadata How do we know that this library is correct? How can we be sure that the library never produces code vulnerable to code injection attacks or other failures of abstraction?
8
8 A Solution Inspired by Dependent Typing SQL Table Schema IdABCD Metaprogram (Static type guarantees correct operation!) Uses type-level computation Code-level iteration over types Guaranteed free of injection vulnerabilities, for any metaprogram input
9
9 table t1 : {Id : int, A : int, B : string, C : float, D : bool} PRIMARY KEY Id open Crud.Make(struct val tab = t1 val title = "Crud1" val cols = {A = Crud.int "A", B = Crud.string "B", C = Crud.float "C", D = Crud.bool "D"} end) An Example Application SQL Table Schema IdABCD Metaprogram Iterate over the structure of this record.
10
10 What's in the Type System? ● Type-level functions: (t. t → t) ● Type-level records: [A = (t. t → t), B = (t. t)] ● Type-level record concatenation: A ++ B ● Type-level map: map (t. t → t) [A = int, B = float] ● Disjointness constraints: [A = int, B = float] ~ r ● Automatic application of algebraic laws – E.g., map f (map g r) = map (f ○ g) r
11
11 Higher-Order Polymorphism HtmlPage adminInterface (Metadata m) { /* iterate over m */ } fun 'T adminInterface (m : 'T Metadata) : HtmlPage = (* iterate over m? *) fun ['T :: Type] adminInterface (m : 'T Metadata) : HtmlPage = (* iterate over m? *) fun ['T :: {Type}] adminInterface (m : $(map Metadata 'T)) (it : 'T Iterator) : HtmlPage = it (* appropriate arguments here... *)
12
12 Ur/Web Available At: http://www.impredicative.com/ur/ Including online demos with syntax-highlighted source code
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.