f ing applicative functors
play

F-ing Applicative Functors Andreas Rossberg, Google Claudio Russo, - PowerPoint PPT Presentation

F-ing Applicative Functors Andreas Rossberg, Google Claudio Russo, MSR Derek Dreyer, MPI-SWS ML Workshop, Copenhagen 2012/09/13 The Functor Schism The Functor Schism SML: generative functors return fresh abstract types with


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

  2. 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

  3. 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)

  4. Purity

  5. 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)

  6. 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

  7. Abstract Values

  8. Abstract Values Every value binding is identified by an abstract value

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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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 ǫ ǫ

  15. F-ing Formalisation

  16. F-ing Elaboration, recap Signatures Γ ⊢ S � ∃ α. Σ Modules Γ ⊢ M : ∃ α. Σ � e

  17. F-ing Elaboration, recap Signatures ⇒ Γ ⊢ ∃ α. Σ :Ω Γ ⊢ S � ∃ α. Σ Modules ⇒ Γ ⊢ e : ∃ α. Σ Γ ⊢ M : ∃ α. Σ � e

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

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

  20. Elaboration, revised Signatures Γ ⊢ S � ∃ α. Σ Modules Γ ⊢ M : ϕ ∃ α. Σ � e ( ϕ ::= P | I )

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

  22. 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

  23. Functor Signatures Γ ⊢ S � ∃ α . Σ

  24. Functor Signatures Γ ⊢ S � ∃ α . Σ Γ ⊢ S 1 � ∃ α 1 . Σ 1 Γ , α 1 , X : Σ 1 ⊢ S 2 � ∃ α 2 . Σ 2 Γ ⊢ ( X : S 1 ) → S 2 � ∀ α 1 . Σ 1 → ∃ α 2 . Σ 2

  25. 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

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

  27. 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 ] }

  28. Functor Expressions Γ ⊢ M : ϕ ∃ α. Σ � e

  29. 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

  30. 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 � ???

  31. Elaboration Invariant, revised Signatures ⇒ Γ ⊢ ∃ α. Σ :Ω Γ ⊢ S � ∃ α. Σ Modules ⇒ Γ ⊢ e : ∃ α. Σ Γ ⊢ M : I ∃ α . Σ � e

  32. Elaboration Invariant, revised Signatures ⇒ Γ ⊢ ∃ α. Σ :Ω Γ ⊢ S � ∃ α. Σ Modules ⇒ Γ ⊢ e : ∃ α. Σ Γ ⊢ M : I ∃ α . Σ � e Γ ⊢ M : P ∃ α. Σ � e

  33. Elaboration Invariant, revised Signatures ⇒ Γ ⊢ ∃ α. Σ :Ω Γ ⊢ S � ∃ α. Σ Modules ⇒ Γ ⊢ e : ∃ α. Σ Γ ⊢ M : I ∃ α . Σ � e ⇒ · ⊢ e : ∃ α. ∀ Γ . Σ Γ ⊢ M : P ∃ α. Σ � e

  34. 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

  35. Sealing Γ ⊢ M : ϕ ∃ α . Σ � e Γ ⊢ Σ ′ ≤ ∃ α. Σ ↑ τ � f Γ( X ) = Σ ′ Γ ⊢ S � ∃ α. Σ Γ ⊢ X : > S : P ∃ α ′ . Σ[ α ′ Γ /α ] � pack � λ Γ .τ, λ Γ .f X � α : κ α ′ : Γ → κ

  36. Elaborating Specifications

  37. Elaborating Specifications Γ ⊢ D � Ξ

  38. Elaborating Specifications Γ ⊢ D � Ξ Γ ⊢ K � κ α Γ ⊢ type X : K � ∃ α. { X : [= α : κ α ] }

  39. Elaborating Specifications Γ ⊢ D � Ξ Γ ⊢ K � κ α Γ ⊢ type X : K � ∃ α. { X : [= α : κ α ] } Γ ⊢ T : κ � τ Γ ⊢ type X = T � { X : [= τ : κ ] }

  40. Elaborating Specifications Γ ⊢ D � Ξ Γ ⊢ K � κ α Γ ⊢ type X : K � ∃ α. { X : [= α : κ α ] } Γ ⊢ T : κ � τ Γ ⊢ type X = T � { X : [= τ : κ ] } Γ ⊢ T : Ω � τ Γ ⊢ val X : T � ∃ α. { X : [= α : Ω] }

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

  42. Elaborating Bindings

  43. Elaborating Bindings Γ ⊢ B : Ξ � e

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend