constructing strictly positive types
play

Constructing Strictly Positive Types A Joint venture of the - PowerPoint PPT Presentation

Constructing Strictly Positive Types A Joint venture of the Nottingham Container Consortium and the Epigram Team Peter Morris w/ Thorsten Altenkirch pwm@cs.nott.ac.uk University of Nottingham Constructing Strictly Positive Types p. 1/10


  1. Constructing Strictly Positive Types A Joint venture of the Nottingham Container Consortium and the Epigram Team Peter Morris w/ Thorsten Altenkirch pwm@cs.nott.ac.uk University of Nottingham Constructing Strictly Positive Types – p. 1/10

  2. First up • This talk is about dependently typed programming, specifically the datatypes we use to do it Constructing Strictly Positive Types – p. 2/10

  3. First up • This talk is about dependently typed programming, specifically the datatypes we use to do it • What we have: data A : ⋆ n : Nat Vec A n : ⋆ where ε : Vec A 0 ; a : A as : Vec A n a : : as : Vec A ( 1 + n ) Constructing Strictly Positive Types – p. 2/10

  4. First up • This talk is about dependently typed programming, specifically the datatypes we use to do it • What we have: data A : ⋆ n : Nat Vec A n : ⋆ where ε : Vec A 0 ; a : A as : Vec A n a : : as : Vec A ( 1 + n ) • + Pattern matching, Structural Recursion. . . Constructing Strictly Positive Types – p. 2/10

  5. What else? • We really want to add more support for the programmer • Reusable libraries of code to use with a range of datatypes • Datatype Generics (Vectors, Lists, Telescopes. . . ) • Remove Boilerplate Constructing Strictly Positive Types – p. 3/10

  6. What else? • We really want to add more support for the programmer • Reusable libraries of code to use with a range of datatypes • Datatype Generics (Vectors, Lists, Telescopes. . . ) • Remove Boilerplate • We’d also like to be able to express the theory of our datatypes in the language • To better define what datatypes ARE • To explain the generation of ⇐ rec and ⇐ case gadgets • To build Epigram in Epigram? Constructing Strictly Positive Types – p. 3/10

  7. data currently Data declarations must conform to Luo’s syntactic test for strict positivity Constructing Strictly Positive Types – p. 4/10

  8. data currently Data declarations must conform to Luo’s syntactic test for strict positivity · · · a : A f : B a → W A B Is OK sup a f : W A B Constructing Strictly Positive Types – p. 4/10

  9. data currently Data declarations must conform to Luo’s syntactic test for strict positivity · · · a : A f : B a → W A B Is OK sup a f : W A B · · · f : ( X → Bool ) → Bool Is not (Negative) c f : X Constructing Strictly Positive Types – p. 4/10

  10. data currently Data declarations must conform to Luo’s syntactic test for strict positivity · · · a : A f : B a → W A B Is OK sup a f : W A B · · · f : ( X → Bool ) → Bool Is not (Negative) c f : X · · · ts : List ( RoseTree A ) Is also rejected. . . node ts : RoseTree a Constructing Strictly Positive Types – p. 4/10

  11. What are containers? Containers have a set of Shapes. S : ⋆ . . . Constructing Strictly Positive Types – p. 5/10

  12. What are containers? Containers have a set of Shapes. S : ⋆ . . . For example: Lists have a shape very similar to the natural numbers. . . ε • • • • • • Constructing Strictly Positive Types – p. 5/10

  13. What are containers? Containers have a set of Shapes. S : ⋆ . . . and for each shape, some set of Positions where data goes P : ∀ s : S ⇒ ⋆ For example: Lists have a shape very similar to the natural numbers. . . and given a shape the set of positions has exactly that many elements ε • • • • • • Constructing Strictly Positive Types – p. 5/10

  14. What are containers? Containers have a set of Shapes. S : ⋆ . . . and for each shape, some set of Positions where data goes P : ∀ s : S ⇒ ⋆ For example: Lists have a shape very similar to the natural numbers. . . and given a shape the set of positions has exactly that many elements ε • • • • • • Closed under: µ, + , × , K → . . . Constructing Strictly Positive Types – p. 5/10

  15. Indexed Containers Are given by: • A Type of Shapes S : ⋆ I , O : ⋆ IC I O : ⋆ where ( | S ⊳ | ) : IC I O Constructing Strictly Positive Types – p. 6/10

  16. Indexed Containers Are given by: • A Type of Shapes • For each shape an Output index. . . S : ⋆ q : S → O I , O : ⋆ IC I O : ⋆ where ( q | S ⊳ | ) : IC I O Constructing Strictly Positive Types – p. 6/10

  17. Indexed Containers Are given by: • A Type of Shapes • For each shape an Output index. . . • and a Type of Positions S : ⋆ q : S → O P : S → ⋆ I , O : ⋆ IC I O : ⋆ where ( q | S ⊳ P | ) : IC I O Constructing Strictly Positive Types – p. 6/10

  18. Indexed Containers Are given by: • A Type of Shapes • For each shape an Output index. . . • and a Type of Positions • And for each position an Input index S : ⋆ q : S → O P : S → ⋆ r : ∀ s : S ⇒ P s → I I , O : ⋆ IC I O : ⋆ where ( q | S ⊳ P | r ) : IC I O Constructing Strictly Positive Types – p. 6/10

  19. Extension The Extension of an Indexed Container ( q | S ⊳ P | r ) : IC I O gives rise to a functor: � q | S ⊳ P | r � : ( I → ⋆ ) → ( O → ⋆ ) Constructing Strictly Positive Types – p. 7/10

  20. Extension The Extension of an Indexed Container ( q | S ⊳ P | r ) : IC I O gives rise to a functor: � q | S ⊳ P | r � : ( I → ⋆ ) → ( O → ⋆ ) which is given by: � q | S ⊳ P | r � X o ⇒ ∃ s : S ⇒ ( o = q s ) × ( ∀ p : P s ⇒ X ( r s p )) Constructing Strictly Positive Types – p. 7/10

  21. What we have done • We have a Universe of Indexed Containers which contains codes for all Strictly Positive Families. Constructing Strictly Positive Types – p. 8/10

  22. What we have done • We have a Universe of Indexed Containers which contains codes for all Strictly Positive Families. • The codes and interpretation are both Epigram datatypes. Constructing Strictly Positive Types – p. 8/10

  23. What we have done • We have a Universe of Indexed Containers which contains codes for all Strictly Positive Families. • The codes and interpretation are both Epigram datatypes. • This gives us a semantic, compositional notion of SPFs in Epigram Constructing Strictly Positive Types – p. 8/10

  24. What we have done • We have a Universe of Indexed Containers which contains codes for all Strictly Positive Families. • The codes and interpretation are both Epigram datatypes. • This gives us a semantic, compositional notion of SPFs in Epigram • Functions in this universe are generic programs. Constructing Strictly Positive Types – p. 8/10

  25. What we have done • We have a Universe of Indexed Containers which contains codes for all Strictly Positive Families. • The codes and interpretation are both Epigram datatypes. • This gives us a semantic, compositional notion of SPFs in Epigram • Functions in this universe are generic programs. • Conclusion? Defining what we really mean by ‘datatype’ can give us Generic programming for all Epigram datatypes Constructing Strictly Positive Types – p. 8/10

  26. SPF data � I : Vec ⋆ n O : ⋆ where SPF � I O : ⋆ T : SPF � I O ‘ Z ’ : SPF ( � ‘ wk ’ T : SPF ( � I : : O ) O I : : I ) O f : ∀ t : Fin n ⇒ SPF � I O ‘ Tag ’ f : SPF � I ( O × Fin n ) ‘ 0 ’ , ‘ 1 ’ : SPF � I O f : O ′ → O T : SPF � T : SPF � f : O → O ′ I O I O ‘ Σ ’ O f T : SPF � ‘ ∆ ’ O f T : SPF � I O ′ I O ′ T : SPF ( � T : SPF � I : : O ) O f : O → O ′ I O ‘ Π ’ O f T : SPF � µ ’ T : SPF � I O ′ ‘ I O Constructing Strictly Positive Types – p. 9/10

  27. El data T : F � T : Tel � � o : O I O I where � T � � T o : ⋆ v : � T � � T � v : � T � � T � X o X o top v : � ‘ Z ’ � ( � pop v : � ‘ wk ’ T � ( � T : : T ) o T : : T ) o v : � f t � � T o tag v : � ‘ Tag ’ f � � T ( o ; t ) void : � ‘ 1 ’ � � T o v : � T � � v : � T � � T ( f o ) T o σ o v : � ‘ Σ ’ f T � � δ v : � ‘ ∆ ’ f T � � T ( f o ) T o v : ∀ o : O ; p : ( f o ) = o ′ � T � � v : � T � ( � T : :( ‘ µ ’ T )) o � T o v : � ‘ Π ’ f T � � µ ’ T � � in v : � ‘ π � T o ′ T o Constructing Strictly Positive Types – p. 10/10

Recommend


More recommend