Overcoming the Schism Support both applicative and generative functors A functor is applicative if and only if it is pure ⇒ type system tracks purity
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
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)
Purity
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)
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 : S 1 ) → S 2 pure: (X : S 1 ) ⇒ S 2
Abstract Values
Abstract Values Every value binding is identified by an abstract value
Abstract Values Every value binding is identified by an abstract value Mere renamings retain identity (e.g., val x = A.y)
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
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
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
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
Module Syntax Modules Signatures S X M X ::= ::= { D } { B } M . X M . X ( X : S ) → S fun X : S ⇒ M ( X : S ) ⇒ S X X S where type X = T X : >S Declarations Bindings D val X : T ::= B val X = E ::= type X = T type X = T type X : K module X = M module X : S signature X = S signature X = S include M include S B ; B D ; D ǫ ǫ
F-ing Formalisation
F-ing Elaboration, recap Signatures Γ ⊢ S � ∃ α. Σ Modules Γ ⊢ M : ∃ α. Σ � e
F-ing Elaboration, recap Signatures ⇒ Γ ⊢ ∃ α. Σ :Ω Γ ⊢ S � ∃ α. Σ Modules ⇒ Γ ⊢ e : ∃ α. Σ Γ ⊢ M : ∃ α. Σ � e
Semantic Signatures, recap Σ ::= [ τ ] (term) | [= τ : κ ] (type) | { l : Σ } (structure) (functor) | ∀ α 1 . Σ 1 → ∃ α 2 . Σ 2
Example: Set Signature Set : (Elem : ORD) → (SET where type elem = Elem.t) ∀ α. { t : [= α : Ω] , leq : [ α → α → bool ] } → ∃ β. { elem : [= α : Ω] , set : [= β : Ω] , empty : [ β ] , add : [ α → β → β ] , member : [ α → β → bool ] }
Elaboration, revised Signatures Γ ⊢ S � ∃ α. Σ Modules Γ ⊢ M : ϕ ∃ α. Σ � e ( ϕ ::= P | I )
Semantic Signatures, revised (path) π ::= α τ (term) Σ ::= [= π : τ ] | [= τ : κ ] (type) (structure) | { l : Σ } (functor) | ∀ α 1 . Σ 2 → ϕ ∃ α 2 . Σ 2
Semantic Signatures, revised (path) π ::= α τ (term) Σ ::= [= π : τ ] | [= τ : κ ] (type) (structure) | { l : Σ } (functor) | ∀ α 1 . Σ 2 → ϕ ∃ α 2 . Σ 2 Impure functor: ∀ α 1 . Σ 1 → I ∃ α 2 . Σ 2 Pure functor: ∃ α 2 . ∀ α 1 . Σ 1 → P Σ 2
Functor Signatures Γ ⊢ S � ∃ α . Σ
Functor Signatures Γ ⊢ S � ∃ α . Σ Γ ⊢ S 1 � ∃ α 1 . Σ 1 Γ , α 1 , X : Σ 1 ⊢ S 2 � ∃ α 2 . Σ 2 Γ ⊢ ( X : S 1 ) → S 2 � ∀ α 1 . Σ 1 → ∃ α 2 . Σ 2
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
Example: Set Signature Set : (Elem : ORD) ⇒ (SET where type elem = Elem.t) ∃ β Ω → Ω . ∀ α . { t : [= α : Ω] , leq : [ α → α → bool ] } → { elem : [= α : Ω] , set : [= β α : Ω] , empty : [ β α ] , add : [ α → β α → β α ] , member : [ α → β α → bool ] }
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 ] }
Functor Expressions Γ ⊢ M : ϕ ∃ α. Σ � e
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
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 � ???
Elaboration Invariant, revised Signatures ⇒ Γ ⊢ ∃ α. Σ :Ω Γ ⊢ S � ∃ α. Σ Modules ⇒ Γ ⊢ e : ∃ α. Σ Γ ⊢ M : I ∃ α . Σ � e
Elaboration Invariant, revised Signatures ⇒ Γ ⊢ ∃ α. Σ :Ω Γ ⊢ S � ∃ α. Σ Modules ⇒ Γ ⊢ e : ∃ α. Σ Γ ⊢ M : I ∃ α . Σ � e Γ ⊢ M : P ∃ α. Σ � e
Elaboration Invariant, revised Signatures ⇒ Γ ⊢ ∃ α. Σ :Ω Γ ⊢ S � ∃ α. Σ Modules ⇒ Γ ⊢ e : ∃ α. Σ Γ ⊢ M : I ∃ α . Σ � e ⇒ · ⊢ e : ∃ α. ∀ Γ . Σ Γ ⊢ M : P ∃ α. Σ � e
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
Sealing Γ ⊢ M : ϕ ∃ α . Σ � e Γ ⊢ Σ ′ ≤ ∃ α. Σ ↑ τ � f Γ( X ) = Σ ′ Γ ⊢ S � ∃ α. Σ Γ ⊢ X : > S : P ∃ α ′ . Σ[ α ′ Γ /α ] � pack � λ Γ .τ, λ Γ .f X � α : κ α ′ : Γ → κ
Elaborating Specifications
Elaborating Specifications Γ ⊢ D � Ξ
Elaborating Specifications Γ ⊢ D � Ξ Γ ⊢ K � κ α Γ ⊢ type X : K � ∃ α. { X : [= α : κ α ] }
Elaborating Specifications Γ ⊢ D � Ξ Γ ⊢ K � κ α Γ ⊢ type X : K � ∃ α. { X : [= α : κ α ] } Γ ⊢ T : κ � τ Γ ⊢ type X = T � { X : [= τ : κ ] }
Elaborating Specifications Γ ⊢ D � Ξ Γ ⊢ K � κ α Γ ⊢ type X : K � ∃ α. { X : [= α : κ α ] } Γ ⊢ T : κ � τ Γ ⊢ type X = T � { X : [= τ : κ ] } Γ ⊢ T : Ω � τ Γ ⊢ val X : T � ∃ α. { X : [= α : Ω] }
Elaborating Specifications Γ ⊢ D � Ξ Γ ⊢ K � κ α Γ ⊢ type X : K � ∃ α. { X : [= α : κ α ] } Γ ⊢ T : κ � τ Γ ⊢ type X = T � { X : [= τ : κ ] } Γ ⊢ T : Ω � τ Γ ⊢ val X : T � ∃ α. { X : [= α : Ω] } Γ ⊢ P : [= π : τ ] � e Γ ⊢ val X = P � { X : [= π : τ ] }
Elaborating Bindings
Elaborating Bindings Γ ⊢ B : Ξ � e
Recommend
More recommend