The Makam metalanguage Reducing the cost of experimentation in PL - - PowerPoint PPT Presentation

the makam metalanguage
SMART_READER_LITE
LIVE PREVIEW

The Makam metalanguage Reducing the cost of experimentation in PL - - PowerPoint PPT Presentation

The Makam metalanguage Reducing the cost of experimentation in PL research Antonis Stampoulis and Adam Chlipala MIT CSAIL 2nd CRSX and HACS User Meetup June 25th, 2014 What do languages of the future look like? Refining language design ideas


slide-1
SLIDE 1

The Makam metalanguage

Reducing the cost of experimentation in PL research Antonis Stampoulis and Adam Chlipala

MIT CSAIL

2nd CRSX and HACS User Meetup June 25th, 2014

slide-2
SLIDE 2

What do languages of the future look like?

slide-3
SLIDE 3

Refining language design ideas until they are “good enough” takes time Need better tooling for experimentation

slide-4
SLIDE 4

Refining language design ideas until they are “good enough” takes time → Need better tooling for experimentation

slide-5
SLIDE 5

Makam is a metalanguage for rapid PL prototyping

  • Main focus is expressivity
  • Can handle modern research programming languages
  • Small, conceptually clear core framework
  • Close correspondence between definitions on paper

and in Makam

  • Prototyping in days instead of months!
slide-6
SLIDE 6

Makam is a metalanguage for rapid PL prototyping

  • Main focus is expressivity
  • Can handle modern research programming languages
  • Small, conceptually clear core framework
  • Close correspondence between definitions on paper

and in Makam

  • Prototyping in days instead of months!
slide-7
SLIDE 7

Contributions

  • The Makam metalanguage design, a refinement of

λProlog

  • Entirely new implementation
  • Set of design patterns addressing common challenges
  • Various large examples: type systems of OCaml, HOL,

VeriML, Ur/Web; part of compilation from System F to TAL

slide-8
SLIDE 8

Overview

slide-9
SLIDE 9

Makam is a typed language

  • Need to declare object-level sorts and constructors

before use

  • Similar to describing abstract syntax on paper

term : type. typ : type. intconst : int -> term. plus : term -> term -> term. app : term -> term -> term. tint : typ. arrow : typ -> typ -> typ.

slide-10
SLIDE 10

Makam is a typed language

  • Need to declare object-level sorts and constructors

before use

  • Similar to describing abstract syntax on paper

term : type. typ : type. intconst : int -> term. plus : term -> term -> term. app : term -> term -> term. tint : typ. arrow : typ -> typ -> typ.

slide-11
SLIDE 11

Makam is a typed language

  • Need to declare object-level sorts and constructors

before use

  • Similar to describing abstract syntax on paper

term : type. typ : type. intconst : int -> term. plus : term -> term -> term. app : term -> term -> term. tint : typ. arrow : typ -> typ -> typ.

slide-12
SLIDE 12

Based on logic programming

  • Predicates for different operations (e.g. typing,

semantics, translations, etc.)

  • Declarative and executable rules

typeof : term -> typ -> prop. eval : term -> term -> prop. typeof (app E1 E2) T’ <- typeof E1 (arrow T T’), typeof E2 T.

slide-13
SLIDE 13

Based on logic programming

  • Predicates for different operations (e.g. typing,

semantics, translations, etc.)

  • Declarative and executable rules

typeof : term -> typ -> prop. eval : term -> term -> prop. typeof (app E1 E2) T’ <- typeof E1 (arrow T T’), typeof E2 T.

slide-14
SLIDE 14

Based on logic programming

  • Predicates for different operations (e.g. typing,

semantics, translations, etc.)

  • Declarative and executable rules

typeof : term -> typ -> prop. eval : term -> term -> prop. typeof (app E1 E2) T’ <- typeof E1 (arrow T T’), typeof E2 T.

slide-15
SLIDE 15

Representing binding

x e x e e x e e v e v x v e e v

  • A common and significant challenge in language

implementation

  • Prolog idea: implement once and for all in the

metalanguage; reuse it in the object languages

slide-16
SLIDE 16

Representing binding

Γ, x : τ ⊢ e : τ ′ Γ ⊢ λx.e : τ → τ ′ e1 ⇓ λx.e e2 ⇓ v2 e[v2/x] ⇓ v′ e1 e2 ⇓ v′

  • A common and significant challenge in language

implementation

  • Prolog idea: implement once and for all in the

metalanguage; reuse it in the object languages

slide-17
SLIDE 17

Representing binding

Γ, x : τ ⊢ e : τ ′ Γ ⊢ λx.e : τ → τ ′ e1 ⇓ λx.e e2 ⇓ v2 e[v2/x] ⇓ v′ e1 e2 ⇓ v′

  • A common and significant challenge in language

implementation

  • λProlog idea: implement once and for all in the

metalanguage; reuse it in the object languages

slide-18
SLIDE 18

Higher-order abstract syntax

lam : (term -> term) -> term. typeof (lam E) (arrow T T’) <- (x:term -> typeof x T -> typeof (E x) T’). eval (app E1 E2) V’ <- eval E1 (lam E), eval E2 V2, eval (E V2) V’.

slide-19
SLIDE 19

Querying

  • Querying for typeof gives us a prototype type checker
  • Querying for eval gives us a prototype interpreter

typeof (lam (fun x => plus x x)) T ? >> T := arrow tint tint

slide-20
SLIDE 20

Querying

  • Querying for typeof gives us a prototype type checker
  • Querying for eval gives us a prototype interpreter

typeof (lam (fun x => plus x x)) T ? >> T := arrow tint tint

slide-21
SLIDE 21

Querying

  • Querying for typeof gives us a prototype type checker
  • Querying for eval gives us a prototype interpreter

typeof (lam (fun x => plus x x)) T ? >> T := arrow tint tint

slide-22
SLIDE 22

Polymorphism & higher-order predicates

map : (A -> B -> prop) -> list A -> list B -> prop. map P (cons HD TL) (cons HD’ TL’) <- P HD HD’, map P TL TL’. map P nil nil. tuple : list term -> term. prod : list typ -> typ. typeof (tuple ES) (prod TS) <- map typeof ES TS.

slide-23
SLIDE 23

Polymorphism & higher-order predicates

map : (A -> B -> prop) -> list A -> list B -> prop. map P (cons HD TL) (cons HD’ TL’) <- P HD HD’, map P TL TL’. map P nil nil. tuple : list term -> term. prod : list typ -> typ. typeof (tuple ES) (prod TS) <- map typeof ES TS.

slide-24
SLIDE 24

Polymorphic binding structures

  • Examples: multiple binding, mutual recursion, linear

variables, etc.

  • Definable within the language

lammany :

  • > term.

typeof (lammany E) (arrowmany TS T) <- newvars_many E (fun xs body => assume_many typeof xs TS (typeof body T)).

slide-25
SLIDE 25

Polymorphic binding structures

  • Examples: multiple binding, mutual recursion, linear

variables, etc.

  • Definable within the language

lammany : (term -> (term -> .... -> term)) -> term. typeof (lammany E) (arrowmany TS T) <- newvars_many E (fun xs body => assume_many typeof xs TS (typeof body T)).

slide-26
SLIDE 26

Polymorphic binding structures

  • Examples: multiple binding, mutual recursion, linear

variables, etc.

  • Definable within the language

lammany : bindmany term term -> term. typeof (lammany E) (arrowmany TS T) <- newvars_many E (fun xs body => assume_many typeof xs TS (typeof body T)).

slide-27
SLIDE 27

Polymorphic binding structures

  • Examples: multiple binding, mutual recursion, linear

variables, etc.

  • Definable within the language

lammany : bindmany term term -> term. typeof (lammany E) (arrowmany TS T) <- newvars_many E (fun xs body => assume_many typeof xs TS (typeof body T)).

slide-28
SLIDE 28

Unification in Makam

  • Based on the higher-order pattern matching

algorithm

  • Means that unification is aware of the HOAS binding

structure

  • Subsumes the core operations of many type

inferencing mechanisms

slide-29
SLIDE 29

Unification in Makam

  • Based on the higher-order pattern matching

algorithm

  • Means that unification is aware of the HOAS binding

structure

  • Subsumes the core operations of many type

inferencing mechanisms

slide-30
SLIDE 30

Unification in Makam

polylam : (typ -> term) -> term. polyinst : term -> typ -> term. forall : (typ -> typ) -> typ. typeof (polylam E) (forall T) <- (a:typ -> typeof (E a) (T a)). typeof (polyinst E T) (T’ T) <- typeof E (pi T’).

slide-31
SLIDE 31

Structural recursion

  • Many operations are defined through structural

recursion save for a few essential cases

  • Usually need lots of boilerplate

expandsugar : term -> term -> prop. expandsugar (lammany E) E’ <- ... expandsugar (app E1 E2) (app E1’ E2’) <- expandsugar E1 E1’, expandsugar E2 E2’. expandsugar (lam E) (lam E’) <- (x:term -> expandsugar x x -> expandsugar (E x) (E’ x)).

slide-32
SLIDE 32

Structural recursion

  • Many operations are defined through structural

recursion save for a few essential cases

  • Usually need lots of boilerplate

expandsugar : term -> term -> prop. expandsugar (lammany E) E’ <- ... expandsugar (app E1 E2) (app E1’ E2’) <- expandsugar E1 E1’, expandsugar E2 E2’. expandsugar (lam E) (lam E’) <- (x:term -> expandsugar x x -> expandsugar (E x) (E’ x)).

slide-33
SLIDE 33

Structural recursion

  • Many operations are defined through structural

recursion save for a few essential cases

  • Usually need lots of boilerplate

expandsugar : term -> term -> prop. expandsugar (lammany E) E’ <- ... expandsugar (app E1 E2) (app E1’ E2’) <- expandsugar E1 E1’, expandsugar E2 E2’. expandsugar (lam E) (lam E’) <- (x:term -> expandsugar x x -> expandsugar (E x) (E’ x)).

slide-34
SLIDE 34

Structural recursion

  • We can define a fully generic structural recursion
  • peration in Makam
  • Relies on dynamic typing unification
  • Works even with auxiliary data structures like list

and bindmany

expandsugar : term -> term -> prop. expandsugar E E’ <- ifte (eq E (lammany _)) (...) (structural expandsugar E E’).

slide-35
SLIDE 35

Structural recursion

  • We can define a fully generic structural recursion
  • peration in Makam
  • Relies on dynamic typing unification
  • Works even with auxiliary data structures like list

and bindmany

expandsugar : term -> term -> prop. expandsugar E E’ <- ifte (eq E (lammany _)) (...) (structural expandsugar E E’).

slide-36
SLIDE 36

Structural recursion

  • We can define a fully generic structural recursion
  • peration in Makam
  • Relies on dynamic typing unification
  • Works even with auxiliary data structures like list

and bindmany

expandsugar : term -> term -> prop. expandsugar E E’ <- ifte (eq E (lammany _)) (...) (structural expandsugar E E’).

slide-37
SLIDE 37

Staging

  • Predicates that compute other predicates, top-level

commands, etc.

  • Allows metalanguage extensions to be defined within

the metalanguage

  • Examples: parser and pretty-printer generation, mode

declarations, etc.

‘( parse term ( ”λ” x:string ”.” e:term lam (nu x e) ) ).

slide-38
SLIDE 38

Staging

  • Predicates that compute other predicates, top-level

commands, etc.

  • Allows metalanguage extensions to be defined within

the metalanguage

  • Examples: parser and pretty-printer generation, mode

declarations, etc.

‘( parse term ( ”λ” x:string ”.” e:term lam (nu x e) ) ).

slide-39
SLIDE 39

Staging

  • Predicates that compute other predicates, top-level

commands, etc.

  • Allows metalanguage extensions to be defined within

the metalanguage

  • Examples: parser and pretty-printer generation, mode

declarations, etc.

‘( parse term ( ”λ” x:string ”.” e:term

{ lam (nu x e) } ) ).

slide-40
SLIDE 40

Examples

OCaml type system 550 lines Type classes 100 lines Higher-order logic 250 lines VeriML constructs 150 lines Featherweight Ur 500 lines System F to TAL 850 lines PEG parser gen 350 lines LF 350 lines

slide-41
SLIDE 41

Summary

  • Makam reduces PL prototyping time from months to

days

  • Small core yet surprisingly expressive
  • Reusable design patterns to handle common

challenges

  • Can already handle sophisticated type systems and

translation procedures

  • Will release publicly mid-July

Thanks!

slide-42
SLIDE 42
slide-43
SLIDE 43

Backup slides

slide-44
SLIDE 44

Staging

and : prop -> prop -> prop. newvar : (A -> prop) -> prop. assume : prop -> prop -> prop. cmd_newconst : string -> A -> cmd. cmd_newrule : prop -> prop -> cmd. cmd_stage : (cmd -> prop) -> cmd.

slide-45
SLIDE 45

Staging

and : prop -> prop -> prop. newvar : (A -> prop) -> prop. assume : prop -> prop -> prop. cmd_newconst : string -> A -> cmd. cmd_newrule : prop -> prop -> cmd. cmd_stage : (cmd -> prop) -> cmd.