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

constructing strictly positive types
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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

slide-2
SLIDE 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

slide-3
SLIDE 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

slide-4
SLIDE 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

slide-5
SLIDE 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

slide-6
SLIDE 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

slide-7
SLIDE 7

data currently

Data declarations must conform to Luo’s syntactic test for strict positivity

Constructing Strictly Positive Types – p. 4/10

slide-8
SLIDE 8

data currently

Data declarations must conform to Luo’s syntactic test for strict positivity · · · a : A f : B a → WA B sup a f : WA B Is OK

Constructing Strictly Positive Types – p. 4/10

slide-9
SLIDE 9

data currently

Data declarations must conform to Luo’s syntactic test for strict positivity · · · a : A f : B a → WA B sup a f : WA B Is OK · · · f : (X → Bool) → Bool c f : X Is not (Negative)

Constructing Strictly Positive Types – p. 4/10

slide-10
SLIDE 10

data currently

Data declarations must conform to Luo’s syntactic test for strict positivity · · · a : A f : B a → WA B sup a f : WA B Is OK · · · f : (X → Bool) → Bool c f : X Is not (Negative) · · · ts : List (RoseTree A) node ts : RoseTree a Is also rejected. . .

Constructing Strictly Positive Types – p. 4/10

slide-11
SLIDE 11

What are containers?

Containers have a set of Shapes. S : ⋆. . .

Constructing Strictly Positive Types – p. 5/10

slide-12
SLIDE 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
slide-13
SLIDE 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
slide-14
SLIDE 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

slide-15
SLIDE 15

Indexed Containers

Are given by:

  • A Type of Shapes

I , O : ⋆ IC I O : ⋆ where S : ⋆ ( |S⊳ | ) : IC I O

Constructing Strictly Positive Types – p. 6/10

slide-16
SLIDE 16

Indexed Containers

Are given by:

  • A Type of Shapes
  • For each shape an Output index. . .

I , O : ⋆ IC I O : ⋆ where S : ⋆ q : S → O (q|S⊳ | ) : IC I O

Constructing Strictly Positive Types – p. 6/10

slide-17
SLIDE 17

Indexed Containers

Are given by:

  • A Type of Shapes
  • For each shape an Output index. . .
  • and a Type of Positions

I , O : ⋆ IC I O : ⋆ where S : ⋆ q : S → O P : S → ⋆ (q|S⊳P| ) : IC I O

Constructing Strictly Positive Types – p. 6/10

slide-18
SLIDE 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

I , O : ⋆ IC I O : ⋆ where S : ⋆ q : S → O P : S → ⋆ r : ∀s : S ⇒ P s → I (q|S⊳P|r) : IC I O

Constructing Strictly Positive Types – p. 6/10

slide-19
SLIDE 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

slide-20
SLIDE 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

slide-21
SLIDE 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

slide-22
SLIDE 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

slide-23
SLIDE 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

slide-24
SLIDE 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

slide-25
SLIDE 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

slide-26
SLIDE 26

SPF

data I : Vec ⋆ n O : ⋆ SPF I O : ⋆ where ‘Z’ : SPF ( I : :O) O T : SPF I O ‘wk’ T : SPF ( 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 I O ‘Σ’O f T : SPF I O′ f : O′ → O T : SPF I O ‘∆’O f T : SPF I O′ f : O → O′ T : SPF I O ‘Π’O f T : SPF I O′ T : SPF ( I : :O) O ‘ µ’ T : SPF I O

Constructing Strictly Positive Types – p. 9/10

slide-27
SLIDE 27

El

data T : F I O

  • T : Tel

I

  • : O

T T o : ⋆ where v : T T X o top v : ‘Z’ ( T: :T) o v : T T X o pop v : ‘wk’ T ( T: :T) o v : f t T o tag v : ‘Tag’f T (o; t) void : ‘1’ T o v : T T o σo v : ‘Σ’f T T (f o) v : T T (f o) δ v : ‘∆’f T T o

  • v : ∀o : O; p : (f o) = o′T

T o π v : ‘Π’f T T o′ v : T ( T: :(‘ µ’ T)) o in v : ‘ µ’ T T o

Constructing Strictly Positive Types – p. 10/10