vectors are records too
play

Vectors are records, too! Jesper Cockx 1 etan Gilbert 2 Ga Nicolas - PowerPoint PPT Presentation

Vectors are records, too! Jesper Cockx 1 etan Gilbert 2 Ga Nicolas Tabareau 2 Matthieu Sozeau 2 1 Gothenburg University, Sweden 2 INRIA, France 21 June 2018 types most popular example 1 data V ( A : Set) : ( n : N ) Set where nil : V A


  1. Vectors are records, too! Jesper Cockx 1 etan Gilbert 2 Ga¨ Nicolas Tabareau 2 Matthieu Sozeau 2 1 Gothenburg University, Sweden 2 INRIA, France 21 June 2018

  2. types ’ most popular example 1 data V ( A : Set) : ( n : N ) → Set where nil : V A zero cons : ( m : N )( x : A )( xs : V A m ) → V A (suc m ) 1 Disclaimer: I did not actually count all examples since 1990. 1 / 15

  3. types ’ most popular example 1 V : ( A : Set)( n : N ) → Set V A zero = ⊤ V A (suc n ) = A × V A n 1 Disclaimer: I did not actually count all examples since 1990. 1 / 15

  4. types ’ most popular example 1 data V ( A : Set) : ( n : N ) → Set where nil : V A zero cons : ( m : N )( x : A )( xs : V A m ) → V A (suc m ) vs. V : ( A : Set)( n : N ) → Set V A zero = ⊤ V A (suc n ) = A × V A n 1 Disclaimer: I did not actually count all examples since 1990. 1 / 15

  5. Presenting. . . A common representation of indexed datatypes and recursive types as case-splitting datatypes . An elaboration algorithm to automatically transform an indexed datatype into a case-splitting datatype. 2 / 15

  6. Inductive types vs. recursive types Case-splitting datatypes Elaborating indexed datatypes

  7. Inductive types vs. recursive types Case-splitting datatypes Elaborating indexed datatypes

  8. Inductive type Recursive type 3 / 15

  9. Inductive type I Recursive type • Intuitive notation data V ( A : Set) : ( n : N ) → Set where nil : V A zero cons : ( m : N )( x : A )( xs : V A m ) → V A (suc m ) 3 / 15

  10. Inductive type I Recursive type I • Intuitive notation • Eta equality x : V A zero ⊢ x ≡ tt x : V A (suc m ) ⊢ x ≡ ( x .π 1 , x .π 2 ) 3 / 15

  11. Inductive type II Recursive type I • Intuitive notation • Eta equality • Pattern matching tail : ( m : N )( xs : V A (suc m )) → V A m tail m (cons ⌊ m ⌋ x xs ) = xs 3 / 15

  12. Inductive type II Recursive type II • Intuitive notation • Eta equality • Pattern matching • Forcing & detagging for free cons : ( m : Nat )( x : A )( xs : V A m ) → V A (suc m ) cons m x xs = ( x , xs ) 3 / 15

  13. Inductive type III Recursive type II • Intuitive notation • Eta equality • Pattern matching • Forcing & detagging for free • Structural recursion 3 / 15

  14. Inductive type III Recursive type III • Intuitive notation • Eta equality • Pattern matching • Forcing & detagging for free • Structural recursion • Large indices ≤ : N → N → Prop zero ≤ n = ⊤ (suc m ) ≤ zero = ⊥ (suc m ) ≤ (suc n ) = m ≤ n 3 / 15

  15. Inductive type IIII Recursive type III • Intuitive notation • Eta equality • Pattern matching • Forcing & detagging for free • Structural recursion • Large indices • Non-indexed / non-stratified types N = ⊤ ⊎ N is not a valid definition! 3 / 15

  16. Inductive type IIII Recursive type IIII • Intuitive notation • Eta equality • Pattern matching • Forcing & detagging for free • Structural recursion • Large indices • Non-indexed / non-stratified types • Non-positive types data U : Set where ⇒ : U → U → U | = : U → Set | =( t 1 ⇒ t 2 ) = | = t 1 → | = t 2 3 / 15

  17. Inductive types vs. recursive types Case-splitting datatypes Elaborating indexed datatypes

  18. data V A : N → Set where Indexed datatype . . . V A zero = . . . Recursive type V A (suc m ) = . . . 4 / 15

  19. data V A : N → Set where Indexed datatype . . . Case-splitting V A n = case n { . . . } datatype V A zero = . . . Recursive type V A (suc m ) = . . . 4 / 15

  20. data V A : N → Set where Indexed datatype . . . ⇑ Case-splitting V A n = case n { . . . } datatype ⇓ V A zero = . . . Recursive type V A (suc m ) = . . . 4 / 15

  21. data V A : N → Set where Indexed datatype . . . ⇑ ⇓ Case-splitting V A n = case n { . . . } datatype ⇓ V A zero = . . . Recursive type V A (suc m ) = . . . 4 / 15

  22. General syntax for case-splitting datatypes Q ::= c 1 ∆ 1 | . . . | c k ∆ k c 1 ˆ  ∆ 1 �→ τ 1 Q 1        .    .    | case x .   c n ˆ  ∆ n �→ τ n Q n          5 / 15

  23. Case tree for V A n   zero �→ nil     case n suc m �→ cons ( x : A )( xs : V A m )     6 / 15

  24. Case tree for m ≤ n  zero �→ lz        suc m ′ �→ case n           case m     zero �→             suc n ′ �→ ls ( p : m ′ ≤ n ′ )               7 / 15

  25. From case tree to a datatype: Ignore case splits; gather all constructors in a flat list. From case tree to a recursive definition: Translate case splits with tools from ‘eliminating dependent pattern matching’. 8 / 15

  26. Inductive types vs. recursive types Case-splitting datatypes Elaborating indexed datatypes

  27. Problem: We don’t want to write case trees, we want to write datatypes! 9 / 15

  28. Problem: We don’t want to write case trees, we want to write datatypes! Solution: Elaborate datatypes to case trees automatically. 9 / 15

  29. State of elaborating a datatype  c 1 ∆ 1 [Φ 1 ]         .    .   ∆ ⊢ .        c k ∆ k [Φ k ]          • ∆ is ‘outer’ telescope of datatype indices • c 1 , . . . , c k are the constructor names • ∆ i is ‘inner’ telescope of arguments of c i • Φ i is a set of constraints { v j / ? p j } 10 / 15

  30. Initial elaboration state ( A : Set)( n : N ) ⊢ [zero / ? n ] { } nil cons ( m : N )( x : A )( xs : V A m ) [suc m / ? n ] 11 / 15

  31. Elaboration step: case split on index ( A : Set)( n : N ) ⊢ [zero / ? n ] { } nil cons ( m : N )( x : A )( xs : V A m ) [suc m / ? n ] ⇓ nil [zero / ? zero] { } ( A : Set) ⊢ ( A : Set)( n ′ : N ) ⊢ cons ( m : N )( x : A )( xs : V A m ) [suc m / ? suc n ′ ] { } 11 / 15

  32. Elaboration step: solve constraint ( A : Set)( n : N ) ⊢ cons ( m : N )( x : A )( xs : V A m ) [suc m / ? suc n ′ ] { } ⇓ { } ( A : Set)( n : N ) ⊢ cons ( x : A )( xs : V A n ′ ) 12 / 15

  33. Elaboration step: finish splitting ( A : Set)( n : N ) ⊢ cons ( m : N )( x : A )( xs : V A m ) [suc m / ? suc n ′ ] { } ⇓ { } ( A : Set)( n : N ) ⊢ cons ( x : A )( xs : V A n ′ ) ⇓ cons ( x : A )( xs : V A n ′ ) 12 / 15

  34. Elaboration step: introduce equality proof image ( x : A ) [ f x / ? y ] { } ( A B : Set)( f : A → B )( y : B ) ⊢ ⇓ { } ( A B : Set)( f : A → B )( y : B ) ⊢ image ( x : A ) ( e : f x ≡ B y ) 13 / 15

  35. Ongoing & future work • Implement translation in Coq (WIP) • Generate constructors & eliminator • Generate case trees for Agda datatypes • User syntax to control splitting? 14 / 15

  36. Conclusion Datatypes have long been denied features of record types such as η -equality. 15 / 15

  37. Conclusion Datatypes have long been denied features of record types such as η -equality. We can automatically transform a datatype into an equivalent definition with η -laws. 15 / 15

  38. Conclusion Datatypes have long been denied features of record types such as η -equality. We can automatically transform a datatype into an equivalent definition with η -laws. Now you can both have the cake and eat it: vectors are records, too! 15 / 15

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