Ur/Web: A Statically-Typed Language for Building Web Applications from Components Adam Chlipala Emerging Languages Camp 2010 Web Applications: A Steaming Pile of Text HTML, CSS, JavaScript, SQL, URLs, JSON, ... Web App Developer Strings, strings, strings, ... Compiler/Interpreter Executive Summary Ur/Web is a domain-specific language with a fancy static type system with first-class support for Web app architecture including strong encapsulation and statically-checked metaprogramming with security by construction Strong Encapsulation Insert Lookup Hash Table Module Interface Client Code 4 Web 1.0 Encapsulation Users Database Table Login Cookie Module Interface Client Code 5 Web 2.0 Encapsulation Subtree of Dynamic Page Structure Module Interface Client Code 6 Automatic Admin Interface Id A B C D Metaprogram SQL Table Schema 7 In-Browser Spreadsheet 8 Metaprogramming in a Nutshell Compile-time Programming Language (AKA, type system) (not Turing complete, but includes basic lambda calculus) Crucial feature: type-level records! Included in Run-time Programming Language (Turing complete) Key Property 1: These types are expressive enough to guarantee absence of code injection, abstraction violation, etc.. Metadata controlling code generation options Metaprogram Sub-Web Key Property 2: Effective static checking that the metaprogram really has the claimed type Metadata's Type-level program type Sub-Web's type 9 An Example Application Id A B C D Metaprogram SQL Table Schema 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 B C D end) = = = = Crud.int "A", Crud.string "B", Crud.float "C", Crud.bool "D"} 10 Nice and Speedy 11 Low Memory Footprint ..... 12 Ur/Web Available At: http://www.impredicative.com/ur/ Including online demos with syntax-highlighted source code 13