bifibrational parametricity
play

Bifibrational Parametricity Federico Orsanigo Strathclyde - PowerPoint PPT Presentation

Bifibrational Parametricity Federico Orsanigo Strathclyde University Fibrations in Computation 2324 June 2014 Joint work with N. Ghani, P. Johann, F. Nordvall Forsberg and T. Revell Parametricity Polymorphic functions are functions


  1. Bifibrational Parametricity Federico Orsanigo Strathclyde University Fibrations in Computation 23–24 June 2014 Joint work with N. Ghani, P. Johann, F. Nordvall Forsberg and T. Revell

  2. Parametricity Polymorphic functions are functions depending on type variables: f : ∀ X . T ( X ) . They can be classified in two classes. ◮ Ad hoc polymorphisms. They define different functions for different types. For example φ : ∀ X . X → X → X can define the sum for natural numbers, concatenetion for lists, . . . ◮ Parametric polymorphisms. They define the same function for any type. For example rev: ∀ X . list ( X ) → list ( X ) defines the same function independently by the type of the list.

  3. Theorems for Free! ◮ From parametric polymorphisms is possible to extract properties. For example any parametric function h : ∀ X . list ( X ) → list ( X ) satisfies h (map f ( xs )) = map f ( h ( xs )) . ◮ This is thanks to Reynolds’ relational interpretation. ◮ Idea: rev(Nat) and rev(Char) come from the same parametric polymorphism, then they are related. ◮ Equality relation performs a central role: closed terms are constant polymorphic functions and related with themselves. ◮ We generalize Reynolds’ model using bifibrations.

  4. Notation ◮ Fibration + Opfibration = Bifibration ◮ Bifibration U : E → B . ◮ The fiber over X is denoted E X . ◮ Let f : X → X ′ be a morphism in B ◮ reindexing functor: f ∗ : E X ′ → E X ◮ opreindexing functor: Σ f : E X → E X ′ ◮ Let f : X → U ( B ) be a morphism in B , the cartesian morphism is denoted f § : f ∗ ( B ) → B . ◮ Let f : U ( A ) → X ′ be a morphism in B , the opcartesian morphism is denoted f § : A → Σ f ( A ).

  5. Setting Definition The category Rel is given by ◮ objects are triples ( A , B , R ) with A , B sets and R ⊆ A × B ◮ morphisms ( f , g ): ( A , B , R ) → ( A ′ , B ′ , R ′ ) with f : A → A ′ , g : B → B ′ and they induce ( f × g ) | R : R → R ′ . Definition We define the functor Rel ( U ): Rel → Set × Set ◮ objects Rel ( U )( A , B , R ) = ( A , B ) ◮ morphisms Rel ( U )( f , g ) = ( f , g ) The functor Rel ( U ): Rel → Set × Set is a bifibration .

  6. Relations Bifibrations We can generalize the previous setting to Definition (Relations Bifibration) Consider a bifibration U : E → B where B has products. The relations bifibration of E over B is Rel ( U ) arising via change of base q ✲ E Rel ( E ) Rel ( U ) U ❄ ❄ ✲ B B × B × The category Rel( E ) has ◮ objects: triple ( A , B , X ) such that U ( X ) = A × B ◮ morphisms: triple ( f , g , α ) such that U ( α ) = f × g We can think X as a relation over A and B . Rel is the relations fibration of Sub( Set ) over Set .

  7. Equality Functor Definition (Truth Functor) If any fiber E X of the fibration U : E → B has terminal object K ( X ) , it induces the functor K : B → E which is called truth functor. Definition (Equality Functor) The equality functor Eq : B → Rel ( E ) for a relations fibration Rel ( U ) : Rel ( E ) → B × B is induced by the action on the objects Eq ( X ) = Σ δ X KX where δ X : X → X × X is diagonal morphism. In Rel this definition gives the usual notion of equality Eq A = { ( a , a ) | a ∈ A }

  8. Types Judgements ◮ A type context Γ is a set of type variables X 1 , . . . , X n . ◮ A type judgement is of the form Γ ⊢ T Type ◮ Type judgements are defined inductively X i ∈ Γ Γ ⊢ X i Type Γ ⊢ T Type Γ ⊢ U Type Γ , X ⊢ T Type Γ ⊢ T → U Type Γ ⊢ ∀ X . T Type We use the more concise notation Γ ⊢ T for type judgements.

  9. Interpretation of Types Reynolds interprets a type judgement with two functors � Γ ⊢ T � 1 : | Rel | n → Rel � Γ ⊢ T � 0 : | Set | n → Set , where | | for discrete categories and n is the cardinality of Γ. The fibrational generalization is with fibred functors � Γ ⊢ T � 1 ✲ Rel ( E ) | Rel ( E ) | n | Rel ( U ) | n Rel ( U ) ❄ ❄ ✲ B × B |B| n × |B| n � Γ ⊢ T � 0 × � Γ ⊢ T � 0

  10. Interpretation of Types in Rel Reynolds’ interpretation: ◮ Type Variables: � Γ ⊢ X i � 0 ¯ � Γ ⊢ X i � 1 ¯ A = A i and R = R i ◮ Arrow Types: we use exponential objects � Γ ⊢ T → U � 0 ¯ � Γ ⊢ T � 0 ¯ A → � Γ ⊢ U � 0 ¯ A = A � Γ ⊢ T → U � 1 ¯ { ( f , g ) | ( a , b ) ∈ � Γ ⊢ T � 1 ¯ = R ⇒ R ( fa , gb ) ∈ � Γ ⊢ U � 1 ¯ R } Note that they are both equality preserving (IEL later) � Γ ⊢ T � 1 (Eq n ¯ A ) → � Γ ⊢ U � 1 (Eq n ¯ A ) ∼ = Eq( � Γ ⊢ T → U � 0 ¯ A )

  11. Forall Types ◮ Set � Γ ⊢ ∀ X . T � 0 ¯ = A { f : ( S : Set ) → � Γ , X ⊢ T � 0 (¯ A , S ) | ( A n +1 , B n +1 , R n +1 ) ∈ Rel ⇒ ( fA n +1 , fB n +1 ) ∈ � Γ , X ⊢ T � 1 ( Eq n ¯ A , R n +1 ) } ◮ ad-hoc functions with an uniformity condition ◮ Rel � Γ ⊢ ∀ X . T � 1 ¯ R = { ( f , g ) | ( A n +1 , B n +1 , R n +1 ) ∈ Rel ⇒ ( fA n +1 , gB n +1 ) ∈ � Γ , X ⊢ T � 1 (¯ R , R n +1 ) } ◮ maps are related iff they map related inputs to related outputs

  12. Interpretation of Types Fibrationally Fibrational interpretation: ◮ Type Variables: � Γ ⊢ X i � 0 ¯ � Γ ⊢ X i � 1 ¯ A = A i and R = R i ◮ Arrow Types: another time exponential objects � Γ ⊢ T → U � 0 ¯ � Γ ⊢ T � 0 ¯ A → � Γ ⊢ U � 0 ¯ = A A � Γ ⊢ T → U � 1 ¯ � Γ ⊢ T � 1 ¯ R → � Γ ⊢ U � 1 ¯ R = R It’s important that they are equality preserving (IEL later) � Γ ⊢ T � 1 (Eq n ¯ A ) → � Γ ⊢ U � 1 (Eq n ¯ A ) ∼ = Eq( � Γ ⊢ T → U � 0 ¯ A )

  13. Forall Types Fibrationally Usually universal quantifier right adjoint of projection. It is important the fibred structure: the adjunction is influenced by the mutually dependence between base and total category. Define | Rel ( U ) | n → Eq Rel ( U ) to be the category of equality preserving fibred functors and fibred natural transformations between them. We interpret ∀ as the right adjoint of the projection functor ◦ π : ( | Rel ( U ) | n → Eq Rel ( U )) → ( | Rel ( U ) | n +1 → Eq Rel ( U ))

  14. Key Theorems in Reynolds’ Model Reynolds’ work is based on two important results: ◮ Identity Extension Lemma , which asserts that equality commutes with the interpretation of types ◮ Abstraction Theorem , which asserts that the interpretation gives maps between relations which preserve relations, i.e. related elements are sent to related elements. We generalize these results to the fibrational setting and compare the statements in Reynolds’ style and in the fibrational one.

  15. Identity Extension Lemma Lemma (IEL, Reynolds-style) If Γ ⊢ T, then for every object ¯ A in Set n � Γ ⊢ T � 1 ( Eq n ¯ A ) = Eq ( � Γ ⊢ T � 0 ¯ A ) The formulation of the IEL fibrational is: Lemma (IEL, Fibrationally) If Γ ⊢ T then � T � is equality preserving, i.e., the following diagram commutes: | Rel ( E ) | n � Γ ⊢ T � 1 ✲ Rel ( E ) | Eq | n ✻ ✻ Eq ✲ B |B| n � Γ ⊢ T � 0

  16. Term Context A term context is of the form Γ ⊢ ∆, where ◮ Γ is a type context ◮ ∆ is of the form x 1 : T 1 , ..., x m : T m ◮ Γ ⊢ T i Type for any i ∈ { 1 , . . . , m } Reynolds interprets term context as pointwise product of types � Γ ⊢ ∆ � 0 = � Γ ⊢ T 1 � 0 × · · · × � Γ ⊢ T n � 0 and � Γ ⊢ ∆ � 1 = � Γ ⊢ T 1 � 1 × · · · × � Γ ⊢ T n � 1 . Given a relations fibration Rel ( U ) in which both the categories have products, it is easy to generalize to the fibred functor � Γ ⊢ ∆ � .

  17. Reynolds’ Interpretation of Terms Reynolds’ set-valued semantics of terms uses induction on the structure of term judgements to give, for each judgement Γ , ∆ ⊢ t : T , a function � Γ , ∆ ⊢ t : T � 0 : (¯ A : | Set | n ) → � Γ ⊢ ∆ � 0 ¯ A → � Γ ⊢ T � 0 ¯ A . It is like we have a map from � Γ ⊢ ∆ � 0 to � Γ ⊢ T � 0 in the environment ¯ A . They can be defined by induction on terms in the expected way.

  18. � � � Terms are Natural Transformations For every object ¯ A of Set n , in Set we have a morphism � Γ ⊢ ∆ � 0 ¯ A → � Γ ⊢ T � 0 ¯ A Both � Γ ⊢ ∆ � 0 and � Γ ⊢ T � 0 define functors | Set | n → Set . We have natural transformation � Γ , ∆ ⊢ t : T � 0 : � Γ ⊢ ∆ � 0 → � Γ ⊢ T � 0 . We write � ∆ � 0 for � Γ ⊢ ∆ � 0 , and � t � 0 for � Γ , ∆ ⊢ t : T � 0 and we can generalize to the fibrational setting as the natural transformation � ∆ � 0 |B| n � � � � � t � 0 B � T � 0

  19. � � � � � � � � Abstraction Theorem Theorem (Abstraction Theorem, Reynolds-Style) Let ¯ A , ¯ B ∈ Set n , ¯ R ∈ Rel n (¯ A , ¯ B ) , ( a , b ) ∈ � Γ ⊢ ∆ � 1 ¯ R then ( � t � 0 ¯ A a , � t � 0 ¯ B b ) ∈ � Γ ⊢ T � 1 ¯ R Theorem (Abstraction Theorem, Fibrationally) Every judgement Γ , ∆ ⊢ t : T defines a fibred natural transformation � t � : � Γ ⊢ ∆ � → � Γ ⊢ T � � ∆ � 1 | Rel ( E ) | n � � Rel ( E ) � � � t � 1 � T � 1 n U U � ∆ � 0 × � ∆ � 0 |B| n × |B| n � � B × B . � � � t � 0 × � t � 0 � T � 0 × � T � 0

Recommend


More recommend