F-ing Applicative Functors

Size: px
Start display at page:

Download "F-ing Applicative Functors"

Transcription

1 F-ing Applicative Functors Andreas Rossberg, Google Claudio Russo, MSR Derek Dreyer, MPI-SWS ML Workshop, Copenhagen 2012/09/13

2 The Functor Schism

3 The Functor Schism SML: generative functors return fresh abstract types with each application

4 The Functor Schism SML: generative functors return fresh abstract types with each application OCaml: applicative functors return same abstract types with each application (to the same argument)

5 The Functor Schism SML: generative functors return fresh abstract types with each application OCaml: applicative functors return same abstract types with each application (to the same argument)

6 Example: Set

7 Example: Set signature SET = { type elem type set val empty : set val add : elem set set val member : elem set bool }

8 Example: Set signature SET = { type elem type set val empty : set val add : elem set set val member : elem set bool } signature ORD = { type t val leq : t t bool }

9 Example: Set signature SET = { type elem type set val empty : set val add : elem set set val member : elem set bool } signature ORD = { type t val leq : t t bool } module Set (Elem : ORD) :> (SET where type elem = Elem.t) = {... }

10 Example: Set, generative module A = Set Int A.member 3 (A.add 2 A.empty)

11 Example: Set, generative module A = Set Int module B = Set Int A.member 3 (B.add 2 B.empty)

12 Example: Set, generative module A = Set Int module B = Set Int A.member 3 (B.add 2 B.empty) (* ill-typed, A.set B.set *)

13 Example: Set, applicative module A = Set Int module B = Set Int A.member 3 (B.add 2 B.empty) (* well-typed, A.set = Set(Int).set = B.set *)

14 The story, so far Leroy [POPL 1995] OCaml Russo [Thesis 1998 / ENTCS 2003] Moscow ML Shao [ICFP 1999] Dreyer & Crary & Harper [POPL 2003]

15 Plan Issues Proposal Formalisation

16 Why applicative functors?

17 Why applicative functors? Literature: motivated by higher-order functors

18 Why applicative functors? Literature: motivated by higher-order functors Practice: compilation units importing functors are higher-order functors in disguise

19 Example: Map signature MAP = { type key type map α val empty : map α val add : key α map α map α val lookup : key map α option α } module Map : (Key : ORD) MAP with type key = Key.t

20 Example: Map signature MAP = { type key type map α val empty : map α val add : key α map α map α val lookup : key map α option α val domain : map α? } module Map : (Key : ORD) MAP with type key = Key.t

21 With generative Set, variant 1 signature MAP = { type key type map α module Set : SET with type elem = key val empty : map α val add : key α map α map α val lookup : key map α option α val domain : map α Set.set } module Map : (Key : ORD) MAP with type key = Key.t

22 With generative Set, variant 2 signature MAP = { type key type map α type set val empty : map α val add : key α map α map α val lookup : key map α option α val domain : map α set } module Map : (Key : ORD) (Set : SET with type elem = Key.t) MAP with type key = Key.t with type set = Set.t

23 With applicative Set signature MAP = { module Key : ORD type map α val empty : map α val add : Key.t α map α map α val lookup : Key.t map α option α val domain : map α Set(Key).set } module Map : (Key : ORD) MAP with type key = Key.t

24 Why applicative functors? Two independent units can use the same generic data type without any need for cooperation A third unit using both is still able to exchange sets between them seamlessly (a.k.a. diamond import)

25 Observation 0 Applicative functors are useful for modularity.

26 Example: First-class modules signature S = { type t; val v : t; val f : t t } val p1 = pack { type t = int; val v = 6; val f = negate } : S val p2 = pack { type t = string; val v = uh ; val f = id } : S

27 Example: First-class modules signature S = { type t; val v : t; val f : t t } val p1 = pack { type t = int; val v = 6; val f = negate } : S val p2 = pack { type t = string; val v = uh ; val f = id } : S val p = ref p1 module F {} = unpack!p : S

28 Example: First-class modules signature S = { type t; val v : t; val f : t t } val p1 = pack { type t = int; val v = 6; val f = negate } : S val p2 = pack { type t = string; val v = uh ; val f = id } : S val p = ref p1 module F {} = unpack!p : S module M1 = F {} p := p2 module M2 = F {}

29 Example: First-class modules signature S = { type t; val v : t; val f : t t } val p1 = pack { type t = int; val v = 6; val f = negate } : S val p2 = pack { type t = string; val v = uh ; val f = id } : S val p = ref p1 module F {} = unpack!p : S module M1 = F {} p := p2 module M2 = F {} M1.f M2.v (* oops, ka-boom! *)

30 Observation 1 Applicativity can break type safety (with 1st-class modules).

31 Example: Abstract names signature NAME = { type name val new : () name val eq : name name bool } module Name {} :> NAME = { type name = int val count = ref 0 val new () = ++count ;!count val eq = Int.eq }

32 Example: Abstract names module A = Name {} module B = Name {} val a = A.new () val b = B.new ()

33 Example: Abstract names module A = Name {} module B = Name {} val a = A.new () val b = B.new () a = b

34 Example: Abstract names module A = Name {} module B = Name {} val a = A.new () val b = B.new () a = b (* oops, true! *)

35 Observation 2 Applicativity can break abstraction safety (of impure functors).

36 Example: Set ordering module A = Set {type t = int; val leq = Int.leq} module B = Set {type t = int; val leq = Int.geq}

37 Example: Set ordering module A = Set {type t = int; val leq = Int.leq} module B = Set {type t = int; val leq = Int.geq} val s1 = A.add 2 A.empty val s2 = B.add 3 s1

38 Example: Set ordering module A = Set {type t = int; val leq = Int.leq} module B = Set {type t = int; val leq = Int.geq} val s1 = A.add 2 A.empty val s2 = B.add 3 s1 A.member 2 s2

39 Example: Set ordering module A = Set {type t = int; val leq = Int.leq} module B = Set {type t = int; val leq = Int.geq} val s1 = A.add 2 A.empty val s2 = B.add 3 s1 A.member 2 s2 (* oops, false! *)

40 Observation 3 Applicativity can break abstraction safety (of pure functors).

41 Example: Set ordering, in Ocaml module A = Set {type t = int; val leq = Int.leq} module B = Set {type t = int; val leq = Int.geq}

42 Example: Set ordering, in Ocaml module A = Set {type t = int; val leq = Int.leq} module B = Set {type t = int; val leq = Int.geq} val s1 = A.add 2 A.empty val s2 = B.add 3 s1

43 Example: Set ordering, in Ocaml module A = Set {type t = int; val leq = Int.leq} module B = Set {type t = int; val leq = Int.geq} val s1 = A.add 2 A.empty val s2 = B.add 3 s1 (* type error, A.set B.set, because Set({...}).set not a path *)

44 Set ordering in Ocaml, take 2

45 Set ordering in Ocaml, take 2 module F (X : {}) = { type t = int val leq = if isfullmoon () then Int.leq else Int.geq }

46 Set ordering in Ocaml, take 2 module F (X : {}) = (* returns one of the previous modules! *) { type t = int val leq = if isfullmoon () then Int.leq else Int.geq }

47 Set ordering in Ocaml, take 2 module F (X : {}) = (* returns one of the previous modules! *) { type t = int val leq = if isfullmoon () then Int.leq else Int.geq } module Unit = {} module A = Set (F Unit) module B = Set (F Unit)

48 Set ordering in Ocaml, take 2 module F (X : {}) = (* returns one of the previous modules! *) { type t = int val leq = if isfullmoon () then Int.leq else Int.geq } module Unit = {} module A = Set (F Unit) module B = Set (F Unit) val s1 = A.add 2 A.empty val s2 = B.add 3 s1 A.member 2 s2

49 Set ordering in Ocaml, take 2 module F (X : {}) = (* returns one of the previous modules! *) { type t = int val leq = if isfullmoon () then Int.leq else Int.geq } module Unit = {} module A = Set (F Unit) module B = Set (F Unit) val s1 = A.add 2 A.empty val s2 = B.add 3 s1 A.member 2 s2 (* oops, false! A.set = Set(F Unit).set = B.set *)

50 Observation 4 Impure applications in paths breaks abstraction safety (even of pure functors).

51 Type Equivalence in Ocaml module A = Set {type t = int; val leq = Int.leq} module B = Set {type t = int; val leq = Int.leq} val s1 = A.add 2 A.empty val s2 = B.add 3 s1 A.member 2 s2 (* type error, A.set B.set, because Set({...}).set not a path *)

52 Type Equivalence in Ocaml (2) module IntOrd = {type t = int; val leq = Int.leq} module IntOrd = IntOrd module A = Set IntOrd module B = Set IntOrd val s1 = A.add 2 A.empty val s2 = B.add 3 s1 A.member 2 s2 (* type error, A.set = Set(IntOrd).set Set(IntOrd ).set = B.set *)

53 Observation 5 Syntactic path equivalence is overly restrictive.

54 Hm...

55 Overcoming the Schism

56 Overcoming the Schism Support both applicative and generative functors

57 Overcoming the Schism Support both applicative and generative functors A functor is applicative if and only if it is pure

58 Overcoming the Schism Support both applicative and generative functors A functor is applicative if and only if it is pure type system tracks purity

59 Overcoming the Schism Support both applicative and generative functors A functor is applicative if and only if it is pure type system tracks purity Two modules are equivalent if and only if they define equivalent types and values

60 Overcoming the Schism Support both applicative and generative functors A functor is applicative if and only if it is pure type system tracks purity Two modules are equivalent if and only if they define equivalent types and values type system tracks value identity (while avoiding dependent types)

61 Purity

62 Purity Only one form of functor expression, deemed pure iff: it does not unpack a first-class module it does not apply an impure functor all value bindings are non-expansive (value restriction)

63 Purity Only one form of functor expression, deemed pure iff: it does not unpack a first-class module it does not apply an impure functor all value bindings are non-expansive (value restriction) Two forms of functor type impure: (X : S1) S2 pure: (X : S1) S2

64 Abstract Values

65 Abstract Values Every value binding is identified by an abstract value

66 Abstract Values Every value binding is identified by an abstract value Mere renamings retain identity (e.g., val x = A.y)

67 Abstract Values Every value binding is identified by an abstract value Mere renamings retain identity (e.g., val x = A.y) Other bindings define fresh abstract value

68 Abstract Values Every value binding is identified by an abstract value Mere renamings retain identity (e.g., val x = A.y) Other bindings define fresh abstract value Specifications (in signatures) declare abstract values

69 Abstract Values Every value binding is identified by an abstract value Mere renamings retain identity (e.g., val x = A.y) Other bindings define fresh abstract value Specifications (in signatures) declare abstract values Formally, abstract values are phantom type variables, quantified and matched in same manner as abstract types

70 Abstract Values Every value binding is identified by an abstract value Mere renamings retain identity (e.g., val x = A.y) Other bindings define fresh abstract value Specifications (in signatures) declare abstract values Formally, abstract values are phantom type variables, quantified and matched in same manner as abstract types Refinement of SML90 s structure sharing

71 Module Syntax Modules M ::= X {B} M.X fun X:S M XX X:>S Signatures S ::= X {D} M.X (X:S) S (X:S) S S where type X=T Bindings B ::= val X=E type X=T module X=M signature X=S include M B;B ɛ Declarations D ::= val X:T type X=T type X:K module X:S signature X=S include S D;D ɛ

72 F-ing Formalisation

73 F-ing Elaboration, recap Signatures Γ S α.σ Modules Γ M : α.σ e

74 F-ing Elaboration, recap Signatures Γ S α.σ Γ α.σ :Ω Modules Γ M : α.σ e Γ e : α.σ

75 Semantic Signatures, recap Σ ::= [τ] [= τ:κ] {l :Σ} α 1.Σ 1 α 2.Σ 2 (term) (type) (structure) (functor)

76 Example: Set Signature Set : (Elem : ORD) (SET where type elem = Elem.t) α.{ t : [= α : Ω], leq :[α α bool] } β. { elem : [= α : Ω], set : [= β : Ω], empty :[β], add :[α β β], member :[α β bool] }

77 Elaboration, revised Signatures Γ S α.σ Modules Γ M : ϕ α.σ e (ϕ ::= P I)

78 Semantic Signatures, revised π ::= α τ Σ ::= [= π:τ] [= τ:κ] {l :Σ} α 1.Σ 2 ϕ α 2.Σ 2 (path) (term) (type) (structure) (functor)

79 Semantic Signatures, revised π ::= α τ Σ ::= [= π:τ] [= τ:κ] {l :Σ} α 1.Σ 2 ϕ α 2.Σ 2 (path) (term) (type) (structure) (functor) Impure functor: Pure functor: α 1.Σ 1 I α 2.Σ 2 α 2. α 1.Σ 1 P Σ 2

80 Functor Signatures Γ S α.σ

81 Functor Signatures Γ S α.σ Γ S 1 α 1.Σ 1 Γ, α 1,X:Σ 1 S 2 α 2.Σ 2 Γ (X:S 1 ) S 2 α 1. Σ 1 α 2.Σ 2

82 Functor Signatures Γ S α.σ Γ S 1 α 1.Σ 1 Γ, α 1,X:Σ 1 S 2 α 2.Σ 2 Γ (X:S 1 ) S 2 α 1. Σ 1 α 2.Σ 2 Γ S 1 α 1.Σ 1 Γ, α 1,X:Σ 1 S 2 α 2.Σ 2 Γ (X:S 1 ) S 2 α 2. α 1. Σ 1 Σ 2 [α 2 α 1/α 2 ] α 1 : κ 1 α 2 : κ 2 α 2 : κ 1 κ 2

83 Example: Set Signature Set : (Elem : ORD) (SET where type elem = Elem.t) β Ω Ω. α.{ t : [= α : Ω], leq :[α α bool] } { elem : [= α : Ω], set : [= βα: Ω], empty :[βα], add :[α βα βα], member :[α βα bool] }

84 Example: Set Signature Set : (Elem : ORD) (SET where type elem = Elem.t) ββ 1 β 2 β 3. αα 1.{ t : [= α : Ω], leq : [= α 1 : α α bool] } { elem : [= α : Ω], set : [= β α α 1 : Ω], empty : [= β 1 : β α α 1 ], add : [= β 2 : α β α α 1 β α α 1 ], member : [= β 3 : α β α α 1 bool] }

85 Functor Expressions Γ M : ϕ α.σ e

86 Functor Expressions Γ M : ϕ α.σ e Γ S α 1.Σ 1 Γ, α 1,X:Σ 1 M : I α 2.Σ 2 e Γ fun X:S M : P α 1. Σ 1 α 2.Σ 2 λα 1.λX:Σ 1.e

87 Functor Expressions Γ M : ϕ α.σ e Γ S α 1.Σ 1 Γ, α 1,X:Σ 1 M : I α 2.Σ 2 e Γ fun X:S M : P α 1. Σ 1 α 2.Σ 2 λα 1.λX:Σ 1.e Γ S α 1.Σ 1 Γ, α 1,X:Σ 1 M : P α 2.Σ 2 e Γ fun X:S M : P α 2. α 1. Σ 1 Σ 2???

88 Elaboration Invariant, revised Signatures Γ S α.σ Γ α.σ :Ω Modules Γ M : I α.σ e Γ e : α.σ

89 Elaboration Invariant, revised Signatures Γ S α.σ Γ α.σ :Ω Modules Γ M : I α.σ e Γ e : α.σ Γ M : P α.σ e

90 Elaboration Invariant, revised Signatures Γ S α.σ Γ α.σ :Ω Modules Γ M : I α.σ e Γ e : α.σ Γ M : P α.σ e e : α. Γ.Σ

91 Functor Expressions Γ M : ϕ α.σ e Γ S α 1.Σ 1 Γ, α 1,X:Σ 1 M : I α 2.Σ 2 e Γ fun X:S M : P α 1. Σ 1 α 2.Σ 2 λγ.λα 1.λX:Σ 1.e Γ S α 1.Σ 1 Γ, α 1,X:Σ 1 M : P α 2.Σ 2 e Γ fun X:S M : P α 2. α 1. Σ 1 Σ 2 e

92 Sealing Γ M : ϕ α.σ e Γ(X) =Σ Γ S α.σ Γ Σ α.σ τ f Γ X :> S: P α.σ[α Γ/α] pack λγ.τ, λγ.f X α : κ α : Γ κ

93 Elaborating Specifications

94 Elaborating Specifications Γ D Ξ

95 Elaborating Specifications Γ K κ α Γ type X:K α.{x : [= α : κ α ]} Γ D Ξ

96 Elaborating Specifications Γ D Ξ Γ K κ α Γ type X:K α.{x : [= α : κ α ]} Γ T : κ τ Γ type X=T {X : [= τ : κ]}

97 Elaborating Specifications Γ D Ξ Γ K κ α Γ type X:K α.{x : [= α : κ α ]} Γ T : κ τ Γ type X=T {X : [= τ : κ]} Γ T :Ω τ Γ val X:T α.{x : [= α : Ω]}

98 Elaborating Specifications Γ D Ξ Γ K κ α Γ type X:K α.{x : [= α : κ α ]} Γ T : κ τ Γ type X=T {X : [= τ : κ]} Γ T :Ω τ Γ val X:T α.{x : [= α : Ω]} Γ P : [= π : τ] e Γ val X=P {X : [= π : τ]}

99 Elaborating Bindings

100 Elaborating Bindings Γ B :Ξ e

101 Elaborating Bindings Γ T : κ τ Γ B :Ξ e Γ type X=T : ϕ {X : [= τ : κ]} {X =[τ : κ]}

102 Elaborating Bindings Γ T : κ τ Γ B :Ξ e Γ type X=T : ϕ {X : [= τ : κ]} {X =[τ : κ]} Γ E : τ e Γ val X=E : I α.{x : [= α : τ]} pack {},{X =[e]}

103 Elaborating Bindings Γ T : κ τ Γ B :Ξ e Γ type X=T : ϕ {X : [= τ : κ]} {X =[τ : κ]} Γ E : τ e Γ val X=E : I α.{x : [= α : τ]} pack {},{X =[e]} Γ E : τ e E non-expansive Γ val X=E : P α.{x : [= α : τ]} pack λγ.{},λγ.{x =[e]}

104 Elaborating Bindings Γ T : κ τ Γ B :Ξ e Γ type X=T : ϕ {X : [= τ : κ]} {X =[τ : κ]} Γ E : τ e Γ val X=E : I α.{x : [= α : τ]} pack {},{X =[e]} Γ E : τ e E non-expansive Γ val X=E : P α.{x : [= α : τ]} pack λγ.{},λγ.{x =[e]} Γ P : ϕ [= π : τ] e Γ val X=P : ϕ {X : [= π : τ]} {X = e}

105 Bonus: Sharing specifications

106 Bonus: Sharing specifications opaque & transparent value specifications val x : t vs. val x = A.y

107 Bonus: Sharing specifications opaque & transparent value specifications val x : t vs. val x = A.y opaque & transparent module specifications module X : S vs. module X = A.Y

108 Bonus: Sharing specifications opaque & transparent value specifications val x : t vs. val x = A.y opaque & transparent module specifications module X : S vs. module X = A.Y value & module refinements S where val X.y = z or S where module X.Y = Z

109 Bonus: Sharing specifications opaque & transparent value specifications val x : t vs. val x = A.y opaque & transparent module specifications module X : S vs. module X = A.Y value & module refinements S where val X.y = z or S where module X.Y = Z singleton signatures like X.Y

110 Conclusion

111 Conclusion Applicative functors are delicate

112 Conclusion Applicative functors are delicate Applicative pure, generative impure

113 Conclusion Applicative functors are delicate Applicative pure, generative impure Module equivalence = type equivalence + value equivalence

114 Conclusion Applicative functors are delicate Applicative pure, generative impure Module equivalence = type equivalence + value equivalence F-ing modules allows fairly elegant formalisation

115 Conclusion Applicative functors are delicate Applicative pure, generative impure Module equivalence = type equivalence + value equivalence F-ing modules allows fairly elegant formalisation Gory details in draft article:

116 Thank you!

117 Outtakes

118 Applicative Semantics for Functors is difficult! Leroy Russo Shao Dreyer+ unrestricted 1stclass modules impure abstraction safe module equivalence no loss of type equivalences Generative functors can be turned applicative after the fact 2 Though you have to try harder

119 Example module Set = fun Elem : ORD { type elem = Elem.t type set = list elem val empty = [] val add x s = case s of [] [x] y :: s' if not (Elem.leq x y) then y :: add x s' else if Elem.leq y x then s else x :: s val mem x s = case s of [] false y :: s' Elem.leq y x and (Elem.leq x y or mem x s') } :> SET where type elem = Elem.t

Derek Dreyer. WG2.8 Meeting, Iceland July 16-20, 2007

Derek Dreyer. WG2.8 Meeting, Iceland July 16-20, 2007 Why Applicative Functors Matter Derek Dreyer Toyota Technological Institute at Chicago WG2.8 Meeting, Iceland July 16-20, 2007 Matthias Felleisen Gets In a Good Jab Matthias Felleisen, POPL PC Chair report,

More information

Calculus INT. Value Types A, B ::= types of the low-level language Interactive Types X, Y ::= [A] A X X Y A X

Calculus INT. Value Types A, B ::= types of the low-level language Interactive Types X, Y ::= [A] A X X Y A X Calculus INT Calculus INT Value Types A, B ::= types of the low-level language Interactive Types X, Y ::= [A] A X X Y A X X Y α A. X α A. X Related: Call-by-Push-Value [Levy 2004] Enrichted Effect Calculus

More information

F-ing modules. Abstract. ZU FPR main 12 December :6

F-ing modules. Abstract. ZU FPR main 12 December :6 Under consideration for publication in J. Functional Programming 1 F-ing modules ANDREAS ROSSBERG Google rossberg@mpi-sws.org and CLAUDIO RUSSO Microsoft Research crusso@microsoft.com and DEREK DREYER

More information

Thesis Proposal: Effective Type Theory for Modularity

Thesis Proposal: Effective Type Theory for Modularity Thesis Proposal: Effective Type Theory for Modularity Derek Dreyer November 21, 2002 School of Computer Science Carnegie Mellon University Pittsburgh, PA 15213 Thesis Committee Robert Harper (co-chair)

More information

TYPE INFERENCE. François Pottier. The Programming Languages Mentoring ICFP August 30, 2015

TYPE INFERENCE. François Pottier. The Programming Languages Mentoring ICFP August 30, 2015 TYPE INFERENCE François Pottier The Programming Languages Mentoring Workshop @ ICFP August 30, 2015 What is type inference? What is the type of this OCaml function? let f verbose msg = if verbose then

More information

Mixin Up the ML Module System

Mixin Up the ML Module System Mixin Up the ML Module System Derek Dreyer and Andreas Rossberg Max Planck Institute for Software Systems Saarbrücken, Germany ICFP 2008 Victoria, British Columbia September 24, 2008 The ML Module System

More information

1ML Core and Modules United (F-ing First-class Modules)

1ML Core and Modules United (F-ing First-class Modules) 1ML Core and Modules United (F-ing First-class Modules) Andreas Rossberg Google, Germany rossberg@mpi-sws.org Abstract ML is two languages in one: there is the core, with types and expressions, and there

More information

1ML with Special Effects

1ML with Special Effects 1ML with Special Effects F-ing Generativity Polymorphism Andreas Rossberg Google, Germany rossberg@mpi-sws.org Abstract. We take another look at 1ML, a language in the ML tradition, but with core and modules

More information

Modules Matter Most. Robert Harper Carnegie Mellon University. MacQueen Fest Chicago May 2012

Modules Matter Most. Robert Harper Carnegie Mellon University. MacQueen Fest Chicago May 2012 Modules Matter Most Robert Harper Carnegie Mellon University MacQueen Fest Chicago May 2012 Thanks... to the organizers for organizing this meeting.... to Dave for being an inspiration to and influence

More information

HOT Compilation: Elaboration

HOT Compilation: Elaboration HOT Compilation: Elaboration TA: Akiva Leffert - aleffert@andrew.cmu.edu Out: Wednesday, October 25, 2005 Due: Wednesday, November 8, 2005 (before midnight) 1 Introduction Elaboration is the first phase

More information

A Type System for Higher-Order Modules

A Type System for Higher-Order Modules A Type System for Higher-Order Modules Derek Dreyer Karl Crary Robert Harper Carnegie Mellon University Abstract We present a type theory for higher-order modules that accounts for many current issues

More information

Type Checking and Type Inference

Type Checking and Type Inference Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

More information

Introduction to OCaml

Introduction to OCaml Fall 2018 Introduction to OCaml Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References Learn X in Y Minutes Ocaml Real World OCaml Cornell CS 3110 Spring 2018 Data Structures and Functional

More information

Tracing Ambiguity in GADT Type Inference

Tracing Ambiguity in GADT Type Inference Tracing Ambiguity in GADT Type Inference ML Workshop 2012, Copenhagen Jacques Garrigue & Didier Rémy Nagoya University / INRIA Garrigue & Rémy Tracing ambiguity 1 Generalized Algebraic Datatypes Algebraic

More information

Some Advanced ML Features

Some Advanced ML Features Some Advanced ML Features Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming University of Washington: Dan Grossman ML is small Small number of powerful constructs

More information

ML Modules and Haskell Type Classes: A Constructive Comparison

ML Modules and Haskell Type Classes: A Constructive Comparison ML Modules and Type Classes: A Constructive Comparison Stefan Wehr 1 and Manuel M. T. Chakravarty 2 1 Institut für Informatik, Universität Freiburg, Georges-Köhler-Allee 079, 79110 Freiburg i. Br., Germany

More information

GADTs meet Subtyping

GADTs meet Subtyping GADTs meet Subtyping Gabriel Scherer, Didier Rémy Gallium INRIA 2014 Gabriel Scherer, Didier Rémy (Gallium INRIA) GADTs meet Subtyping 2014 1 / 21 A reminder on GADTs GADTs are algebraic data types that

More information

First-Class Type Classes

First-Class Type Classes First-Class Type Classes Matthieu Sozeau Joint work with Nicolas Oury LRI, Univ. Paris-Sud - Démons Team & INRIA Saclay - ProVal Project Gallium Seminar November 3rd 2008 INRIA Rocquencourt Solutions for

More information

The Recursive Module Problem

The Recursive Module Problem Chapter 5 The Recursive Module Problem Recursive modules are one of the most frequently requested extensions to the ML languages. After all, the ability to have cyclic depencies between pieces of code

More information

Adding GADTs to OCaml the direct approach

Adding GADTs to OCaml the direct approach Adding GADTs to OCaml the direct approach Jacques Garrigue & Jacques Le Normand Nagoya University / LexiFi (Paris) https://sites.google.com/site/ocamlgadt/ Garrigue & Le Normand Adding GADTs to OCaml 1

More information

1 Introduction. 3 Syntax

1 Introduction. 3 Syntax CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,

More information

Higher-order modules in System F ω and Haskell

Higher-order modules in System F ω and Haskell Higher-order modules in System F ω and Haskell Chung-chieh Shan Harvard University ccshan@post.harvard.edu Abstract To argue that it is practical to extend core Haskell to support higher-order modules,

More information

OCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type.

OCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type. OCaml The PL for the discerning hacker. ML Flow Expressions (Syntax) Compile-time Static 1. Enter expression 2. ML infers a type Exec-time Dynamic Types 3. ML crunches expression down to a value 4. Value

More information

CSE-321: Assignment 8 (100 points)

CSE-321: Assignment 8 (100 points) CSE-321: Assignment 8 (100 points) gla@postech.ac.kr Welcome to the final assignment of CSE-321! In this assignment, you will implement a type reconstruction algorithm (the algorithm W discussed in class)

More information

Polymorphic Delimited Continuations

Polymorphic Delimited Continuations Polymorphic Delimited Continuations Kenichi Asai Ochanomizu University Yukiyoshi Kameyama University of Tsukuba November 30, 2007 Outline of the talk 1. The language: λ-calculus + let + shift/reset 2.

More information

Type structure is a syntactic discipline for maintaining levels of abstraction John Reynolds, Types, Abstraction and Parametric Polymorphism

Type structure is a syntactic discipline for maintaining levels of abstraction John Reynolds, Types, Abstraction and Parametric Polymorphism Chapter 6 Abstraction Type structure is a syntactic discipline for maintaining levels of abstraction John Reynolds, Types, Abstraction and Parametric Polymorphism Abstraction, also known as information

More information

l e t print_name r = p r i n t _ e n d l i n e ( Name : ^ r. name)

l e t print_name r = p r i n t _ e n d l i n e ( Name : ^ r. name) Chapter 8 Row polymorphism Consider the following code: type name_home = {name : s t r i n g ; home : s t r i n g } type name_mobile = {name : s t r i n g ; mobile : s t r i n g } l e t jane = {name =

More information

A Type System for Well-Founded Recursion

A Type System for Well-Founded Recursion A Type System for Well-Founded Recursion Derek Dreyer Robert Harper Karl Crary July 2003 CMU-CS-03-163 School of Computer Science Carnegie Mellon University Pittsburgh, PA 15213 Abstract In the interest

More information

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages Call-by-value Operational Semantics

More information

Advanced Type System Features Tom Schrijvers. Leuven Haskell User Group

Advanced Type System Features Tom Schrijvers. Leuven Haskell User Group Advanced Type System Features Tom Schrijvers Leuven Haskell User Group Data Recursion Genericity Schemes Expression Problem Monads GADTs DSLs Type Type Families Classes Lists and Effect Free Other Handlers

More information

A Modular Package Language for Haskell

A Modular Package Language for Haskell A Modular Package Language for Haskell Scott Kilpatrick MPI-SWS Joint work with: Derek Dreyer (MPI-SWS) Simon Marlow (Microsoft Research) Simon Peyton Jones (Microsoft Research) University of Pennsylvania

More information

CSE3322 Programming Languages and Implementation

CSE3322 Programming Languages and Implementation Monash University School of Computer Science & Software Engineering Sample Exam 2004 CSE3322 Programming Languages and Implementation Total Time Allowed: 3 Hours 1. Reading time is of 10 minutes duration.

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha 10/3/17

More information

Introduction to SML Getting Started

Introduction to SML Getting Started Introduction to SML Getting Started Michael R. Hansen mrh@imm.dtu.dk Informatics and Mathematical Modelling Technical University of Denmark c Michael R. Hansen, Fall 2004 p.1/15 Background Standard Meta

More information

Some instance messages and methods

Some instance messages and methods Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x

More information

MetaML: structural reflection for multi-stage programming (CalcagnoC, MoggiE, in collaboration with TahaW)

MetaML: structural reflection for multi-stage programming (CalcagnoC, MoggiE, in collaboration with TahaW) Workshop TOSCA MetaML: structural reflection for multi-stage programming (CalcagnoC, MoggiE, in collaboration with TahaW) - starting point: functional languages, MetaML [MetaML] - keywords: programs as

More information

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming The ML Programming Language General purpose programming language designed by Robin Milner in 1970 Meta Language

More information

User-Defined Algebraic Data Types

User-Defined Algebraic Data Types 72 Static Semantics User-Defined Types User-Defined Algebraic Data Types An algebraic data type declaration has the general form: data cx T α 1... α k = K 1 τ 11... τ 1k1... K n τ n1... τ nkn introduces

More information

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 11 February 5, 2018 Review: Abstract types Finite Maps Homework 3 due tomorrow at 11:59:59pm Announcements (Homework 4 is due Tuesday, 2/20, and won

More information

DEFINING A LANGUAGE. Robert Harper. Friday, April 27, 12

DEFINING A LANGUAGE. Robert Harper. Friday, April 27, 12 DEFINING A LANGUAGE Robert Harper ACKNOWLEDGEMENTS I am honored to have had the privilege of working with Robin on the development of Standard ML. It is also a pleasure to thank my collaborators, Karl

More information

Variables. Substitution

Variables. Substitution Variables Elements of Programming Languages Lecture 4: Variables, binding and substitution James Cheney University of Edinburgh October 6, 2015 A variable is a symbol that can stand for another expression.

More information

COS 320. Compiling Techniques

COS 320. Compiling Techniques Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly

More information

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Fall 2017 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory All

More information

Continuation Passing Style. Continuation Passing Style

Continuation Passing Style. Continuation Passing Style 161 162 Agenda functional programming recap problem: regular expression matcher continuation passing style (CPS) movie regular expression matcher based on CPS correctness proof, verification change of

More information

The Design of Core C++ (Notes)

The Design of Core C++ (Notes) The Design of Core C++ (Notes) Uday Reddy May 13, 1994 This note is to define a small formal language called Core C++ which reflects the essential structure of C++. As the name implies, the design only

More information

ML Modules and Haskell Type Classes: A Constructive Comparison

ML Modules and Haskell Type Classes: A Constructive Comparison ML Modules and Haskell Type Classes: A Constructive Comparison Stefan Wehr 1 and Manuel M. T. Chakravarty 2 1 Institut für Informatik, Universität Freiburg, Georges-Köhler-Allee 079, 79110 Freiburg i.

More information

Part VI. Imperative Functional Programming

Part VI. Imperative Functional Programming Part VI Imperative Functional Programming Chapter 14 Mutable Storage MinML is said to be a pure language because the execution model consists entirely of evaluating an expression for its value. ML is

More information

A Type System for Recursive Modules

A Type System for Recursive Modules A Type System for Recursive Modules Derek Dreyer Toyota Technological Institute Chicago, Illinois, USA dreyer@tti-c.org Abstract There has been much work in recent years on exting ML with recursive modules.

More information

Handout 2 August 25, 2008

Handout 2 August 25, 2008 CS 502: Compiling and Programming Systems Handout 2 August 25, 2008 Project The project you will implement will be a subset of Standard ML called Mini-ML. While Mini- ML shares strong syntactic and semantic

More information

The design of a programming language for provably correct programs: success and failure

The design of a programming language for provably correct programs: success and failure The design of a programming language for provably correct programs: success and failure Don Sannella Laboratory for Foundations of Computer Science School of Informatics, University of Edinburgh http://homepages.inf.ed.ac.uk/dts

More information

Last time: generic programming

Last time: generic programming 1/ 55 Last time: generic programming val (=) : { D: DATA } D. t D. t bool 2/ 55 This time: monads etc., continued >>= effect E 3/ 55 Recap: monads, bind and let An imperative program let id =! counter

More information

Last time: generic programming

Last time: generic programming 1/ 45 Last time: generic programming val show : a data a string 2/ 45 This time: staging.< e >. 3/ 45 Review: abstraction Lambda abstraction λx : A.M ΛA :: K.M λa :: K.B Abstraction of type equalities

More information

Recap: Functions as first-class values

Recap: Functions as first-class values Recap: Functions as first-class values Arguments, return values, bindings What are the benefits? Parameterized, similar functions (e.g. Testers) Creating, (Returning) Functions Iterator, Accumul, Reuse

More information

News. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012

News. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012 News CSE 130: Spring 2012 Programming Languages On webpage: Suggested HW #1 PA #1 (due next Fri 4/13) Lecture 2: A Crash Course in ML Please post questions to Piazza Ranjit Jhala UC San Diego Today: A

More information

Pattern Matching and Abstract Data Types

Pattern Matching and Abstract Data Types Pattern Matching and Abstract Data Types Tom Murphy VII 3 Dec 2002 0-0 Outline Problem Setup Views ( Views: A Way For Pattern Matching To Cohabit With Data Abstraction, Wadler, 1986) Active Patterns (

More information

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context Types 1 / 15 Outline Introduction Concepts and terminology The case for static typing Implementing a static type system Basic typing relations Adding context 2 / 15 Types and type errors Type: a set of

More information

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Spring 2018 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory

More information

Functional Programming and Haskell

Functional Programming and Haskell Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming

More information

Goal. CS152: Programming Languages. Lecture 15 Parametric Polymorphism. What the Library Likes. What The Client Likes. Start simpler.

Goal. CS152: Programming Languages. Lecture 15 Parametric Polymorphism. What the Library Likes. What The Client Likes. Start simpler. Goal Understand what this interface means and why it matters: CS152: Programming Languages Lecture 15 Parametric Polymorphism Dan Grossman Spring 2011 type a mylist; val mt_list : a mylist val cons : a

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation

More information

Structural polymorphism in Generic Haskell

Structural polymorphism in Generic Haskell Structural polymorphism in Generic Haskell Andres Löh andres@cs.uu.nl 5 February 2005 Overview About Haskell Genericity and other types of polymorphism Examples of generic functions Generic Haskell Overview

More information

Abstraction. Leo White. February Jane Street 1/ 88

Abstraction. Leo White. February Jane Street 1/ 88 1/ 88 Abstraction Leo White Jane Street February 2017 2/ 88 Abstraction When faced with creating and maintaining a complex system, the interactions of different components can be simplified by hiding the

More information

Modular implicits for OCaml how to assert success. Gallium Seminar,

Modular implicits for OCaml how to assert success. Gallium Seminar, Modular implicits for OCaml how to assert success Jacques Garrigue Nagoya University Frédéric Bour Sponsored by Jane Street LLC Gallium Seminar, 14-03-2016 Garrigue & Bour Mdular implicits and success

More information

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

CMSC 330: Organization of Programming Languages. Functional Programming with Lists CMSC 330: Organization of Programming Languages Functional Programming with Lists CMSC330 Spring 2018 1 Lists in OCaml The basic data structure in OCaml Lists can be of arbitrary length Implemented as

More information

Lecture #23: Conversion and Type Inference

Lecture #23: Conversion and Type Inference Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:

More information

Modular Type Classes

Modular Type Classes Modular Type Classes Derek Dreyer Toyota Technological Institute at Chicago dreyer@tti-c.org Robert Harper Carnegie Mellon University rwh@cs.cmu.edu Manuel M.T. Chakravarty University of New South Wales

More information

Scope and Introduction to Functional Languages. Review and Finish Scoping. Announcements. Assignment 3 due Thu at 11:55pm. Website has SML resources

Scope and Introduction to Functional Languages. Review and Finish Scoping. Announcements. Assignment 3 due Thu at 11:55pm. Website has SML resources Scope and Introduction to Functional Languages Prof. Evan Chang Meeting 7, CSCI 3155, Fall 2009 Announcements Assignment 3 due Thu at 11:55pm Submit in pairs Website has SML resources Text: Harper, Programming

More information

CSCE 314 Programming Languages Functors, Applicatives, and Monads

CSCE 314 Programming Languages Functors, Applicatives, and Monads CSCE 314 Programming Languages Functors, Applicatives, and Monads Dr. Hyunyoung Lee 1 Motivation Generic Functions A common programming pattern can be abstracted out as a definition. For example: inc ::

More information

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";

Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = Hello; Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";

More information

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming The ML Programming Language General purpose programming language designed by Robin Milner in 1970 Meta Language

More information

Chapter 3 Linear Structures: Lists

Chapter 3 Linear Structures: Lists Plan Chapter 3 Linear Structures: Lists 1. Lists... 3.2 2. Basic operations... 3.4 3. Constructors and pattern matching... 3.5 4. Polymorphism... 3.8 5. Simple operations on lists... 3.11 6. Application:

More information

1. Abstract syntax: deep structure and binding. 2. Static semantics: typing rules. 3. Dynamic semantics: execution rules.

1. Abstract syntax: deep structure and binding. 2. Static semantics: typing rules. 3. Dynamic semantics: execution rules. Introduction Formal definitions of programming languages have three parts: CMPSCI 630: Programming Languages Static and Dynamic Semantics Spring 2009 (with thanks to Robert Harper) 1. Abstract syntax:

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 10 February 5 th, 2016 Abstract types: sets Lecture notes: Chapter 10 What is the value of this expresssion? let f (x:bool) (y:int) : int = if x then

More information

02157 Functional Programming. Michael R. Ha. Lecture 3: Programming as a model-based activity. Michael R. Hansen

02157 Functional Programming. Michael R. Ha. Lecture 3: Programming as a model-based activity. Michael R. Hansen Lecture 3: as a model-based activity nsen 1 DTU Compute, Technical University of Denmark Lecture 3: as a model-based activity MRH 20/09/2018 Overview RECAP Higher-order functions (lists) Type inference

More information

Reference Cells. Example

Reference Cells. Example Introduction to Objective Caml Part 2 Stefan Wehr University of Freiburg. November 8, 2006 Remember: Variables are only names for values Can t asn to variables Solution: reference cells Constructor: ref

More information

A Unifying Account of ML Modules

A Unifying Account of ML Modules Chapter 2 A Unifying Account of ML Modules The previous chapter gave a brief survey of several concepts that stand as key points of contention in the design of the ML module system, including applicative

More information

At build time, not application time. Types serve as statically checkable invariants.

At build time, not application time. Types serve as statically checkable invariants. Static Typing Thus far we have only considered statically typed languages. CMPSCI 630: Programming Languages Static and Dynamic Typing Spring 2008 (with thanks to Robert Harper) Type system is based on

More information

Mutable References. Chapter 1

Mutable References. Chapter 1 Chapter 1 Mutable References In the (typed or untyped) λ-calculus, or in pure functional languages, a variable is immutable in that once bound to a value as the result of a substitution, its contents never

More information

CSE-321 Programming Languages 2014 Final

CSE-321 Programming Languages 2014 Final Name: Hemos ID: CSE-321 Programming Languages 2014 Final Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Problem 6 Total Score Max 15 12 14 14 30 15 100 There are six problems on 12 pages in this exam.

More information

CSE-321 Programming Languages 2010 Midterm

CSE-321 Programming Languages 2010 Midterm Name: Hemos ID: CSE-321 Programming Languages 2010 Midterm Score Prob 1 Prob 2 Prob 3 Prob 4 Total Max 15 30 35 20 100 1 1 SML Programming [15 pts] Question 1. [5 pts] Give a tail recursive implementation

More information

Chapter 3 Linear Structures: Lists

Chapter 3 Linear Structures: Lists Plan Chapter 3 Linear Structures: Lists 1. Two constructors for lists... 3.2 2. Lists... 3.3 3. Basic operations... 3.5 4. Constructors and pattern matching... 3.6 5. Simple operations on lists... 3.9

More information

Typed Compilation of Recursive Datatypes

Typed Compilation of Recursive Datatypes Typed Compilation of Recursive Datatypes Joseph C. Vanderwaart Derek Dreyer Leaf Petersen Karl Crary Robert Harper Perry Cheng School of Computer Science Carnegie Mellon University Pittsburgh, PA 15213

More information

Parametricity. Leo White. February Jane Street 1/ 70

Parametricity. Leo White. February Jane Street 1/ 70 1/ 70 Parametricity Leo White Jane Street February 2017 2/ 70 Parametricity Polymorphism allows a single piece of code to be instantiated with multiple types. Polymorphism is parametric when all of the

More information

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference

Lecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference Lecture #13: Type Inference and Unification Typing In the Language ML Examples from the language ML: fun map f [] = [] map f (a :: y) = (f a) :: (map f y) fun reduce f init [] = init reduce f init (a ::

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 10 February 2, 2018 Abstract types: Sets Chapter 10 Announcements Homework 3 due Tuesday at 11:59:59pm Midterm 1 Friday, February 9, in class Covers

More information

Recitation 6: System F and Existential Types : Foundations of Programming Languages

Recitation 6: System F and Existential Types : Foundations of Programming Languages Recitation 6: System F and Existential Types 15-312: Foundations of Programming Languages Serena Wang, Charles Yuan February 21, 2018 We saw how to use inductive and coinductive types last recitation.

More information

Agenda. CS301 Session 11. Common type constructors. Things we could add to Impcore. Discussion: midterm exam - take-home or inclass?

Agenda. CS301 Session 11. Common type constructors. Things we could add to Impcore. Discussion: midterm exam - take-home or inclass? Agenda CS301 Session 11 Discussion: midterm exam - take-home or inclass? Interlude: common type constructors Type soundness 1 2 Things we could add to Impcore Common type constructors Array is a type constructor,

More information

Programming Languages

Programming Languages CSE 130: Fall 2009 Programming Languages Lecture 2: A Crash Course in ML News On webpage: Suggested HW #1 PA #1 (due next Fri 10/9) Technical issues installing Ocaml - should be resolved soon! Ranjit Jhala

More information

Programming Languages Lecture 15: Recursive Types & Subtyping

Programming Languages Lecture 15: Recursive Types & Subtyping CSE 230: Winter 2008 Principles of Programming Languages Lecture 15: Recursive Types & Subtyping Ranjit Jhala UC San Diego News? Formalize first-order type systems Simple types (integers and booleans)

More information

Open Modules: Modular Reasoning in Aspect-Oriented Programming

Open Modules: Modular Reasoning in Aspect-Oriented Programming Open Modules: Modular Reasoning in Aspect-Oriented Programming Jonathan Aldrich School of Computer Science Carnegie Mellon University 5000 Forbes Avenue Pittsburgh, PA 15213, USA jonathan.aldrich@cs.cmu.edu

More information

CS421 Spring 2014 Midterm 1

CS421 Spring 2014 Midterm 1 CS421 Spring 2014 Midterm 1 Name: NetID: You have 75 minutes to complete this exam. This is a closed-book exam. All other materials (e.g., calculators, telephones, books, card sheets), except writing utensils

More information

CSE-505: Programming Languages. Lecture 18 Existential Types. Zach Tatlock 2016

CSE-505: Programming Languages. Lecture 18 Existential Types. Zach Tatlock 2016 CSE-505: Programming Languages Lecture 18 Existential Types Zach Tatlock 2016 Back to our goal Understand this interface and its nice properties: type a mylist; val mt_list : a mylist val cons : a -> a

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language

More information

If a program is well-typed, then a type can be inferred. For example, consider the program

If a program is well-typed, then a type can be inferred. For example, consider the program CS 6110 S18 Lecture 24 Type Inference and Unification 1 Type Inference Type inference refers to the process of determining the appropriate types for expressions based on how they are used. For example,

More information

Programming with Types

Programming with Types Programming with Types Run-time type analysis and the foundations of program reflection Stephanie Weirich Cornell University Reflection A style of programming that supports the run-time discovery of program

More information

Agenda. CS301 Session 9. Abstract syntax: top level. Abstract syntax: expressions. The uscheme interpreter. Approaches to solving the homework problem

Agenda. CS301 Session 9. Abstract syntax: top level. Abstract syntax: expressions. The uscheme interpreter. Approaches to solving the homework problem CS301 Session 9 The uscheme interpreter Agenda Approaches to solving the homework problem 1 2 Abstract syntax: top level datatype toplevel = EXP of exp DEFINE of name * lambda VAL of name * exp USE of

More information

CS153: Compilers Lecture 15: Local Optimization

CS153: Compilers Lecture 15: Local Optimization CS153: Compilers Lecture 15: Local Optimization Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 4 out Due Thursday Oct 25 (2 days) Project 5 out Due Tuesday Nov 13 (21 days)

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) #3: Closures, evaluation of function applications, order of evaluation #4: Evaluation and Application rules using symbolic rewriting Madhusudan Parthasarathy

More information

CIS 500 Software Foundations Fall December 6

CIS 500 Software Foundations Fall December 6 CIS 500 Software Foundations Fall 2006 December 6 Administrivia Administrivia No recitations this week Extra office hours will be posted to the class mailing list Exam: Wednesday, Dec 20, 9 11 Location:

More information