24
On the Algebraic Definition of Programming Languages Ambrus Kaposi 1 1 otv¨ os Lor´ and University 8 May 2020, online

On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

On the Algebraic Definition ofProgramming Languages

Ambrus Kaposi1

1Eotvos Lorand University

8 May 2020, online

Page 2: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Software crisis

Complex systems, many bugs.

How do we improve existing software?

Develop tools toI test code (Attila Kovacs)I analyse code (Melinda Toth, Istvan Bozo)I refactor code in a correct way (Daniel Horpacsi)

Page 3: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Software crisis

Complex systems, many bugs.

How do we improve future software?

Develop new programming languagesI it should be easy to write correct codeI hard to write incorrect code

Page 4: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Why do we need different programming languages?

Programming languages are the same:I They are just different ways to express CPU instructions.I They are all Turing-complete.

They are not the same:I If the language suits the problem, we can express the solution directly.I If not, we need to encode the solution.

Page 5: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Why do we need different programming languages?

Programming languages are the same:I They are just different ways to express CPU instructions.I They are all Turing-complete.

They are not the same:I If the language suits the problem, we can express the solution directly.I If not, we need to encode the solution.

Page 6: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Programming is the process of encoding

Domain specific languages:I HTML for hypertextI P4 for programming switches (Sandor Laki)I Erlang for programming mobile networks, distributed systemsI Alan Kay’s example:

I operating system with GUI, web browser, spreadsheet, word processorI all in 20thousand lines of code

Page 7: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Difficulties of creating new languages

I Design the language such that it is soundI Prove its properties

I Implementation, lots of technical detailsI Improvements recently, e.g. LLVM

I Interface to other languages

People usually don’t bother: instead, they follow the hammer principle.

Page 8: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a domain specific language for describing languages?

This is our research project.

What is a language?

A language is a collection of programs.

What is a program?

Page 9: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise

Page 10: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise

Page 11: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise

Page 12: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise

Page 13: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise

Page 14: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise

Page 15: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise

Page 16: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise 1 + 2+

1 2

1 + ”dog”+

1 ”dog”

Page 17: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

What is a program?

(1) number

(2) string

(3) syntax tree

(4) syntax tree with bindings

(5) well typed syntax

(6) well typed syntax quotiented

decode

parsing

scope checking

type checking

encode

print

pick variable names

normalise 1 + 2 = 3

+

1 2= 3

Page 18: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

A language is a collection of:

+

1 2= 3

Mathematicians call this ageneralised algebraic structure, programmerscall it a quotient inductive-inductive type.

Page 19: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Results

I We created the first programming language which supportsquotient inductive-inductive types (QIIT).I It is based on Martin-Lof’s type theory and we call it setoid type theory.I Syntax (as a QIIT) and constructive semantics.I A prototype implementation in Haskell.

I We developed the metatheory of QIITs.I A concrete description.I We proved their consistency, constructive semantics.

I We developed techniques to formalise metatheoretic results in existing languagesbased on type theory.

Page 20: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Further goals

I Theoretical: show decidability of type checking for setoid type theoryI Theoretical: reduction of QIITs to basic combinatorsI Practical: industrial strength implementationI Practical: implement existing programming languages as QIITsI Long term: implement setoid type theory in itself

Page 21: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Team and collaborators

Page 22: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Summary

I A good programming language admits direct representations of the domainI Programming languages are usually encoded instead of directly representedI Our hypothesis: the reason for this is that there is no programming language

supporting QIITsI We are developing such a language: the theoretical foundations are mostly doneI We would like to develop a practical implementation

Page 23: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

Q&A

Page 24: On the Algebraic Definition of Programming Languages...Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol 11825. Springer, Cham I

References

I Yoshiki Ohshima, Ted Kaehler Dan Amelang, Bert Freudenberg, Aran Lunzer, Ian Piumarta Alan Kay, TakashiYamamiya, Hesam Samimi Alan Borning, Bret Victor, and Kim Rose, Steps toward the reinvention ofprogramming, 2012 final report. Submitted to the National Science Foundation (NSF).

I Thorsten Altenkirch and Ambrus Kaposi. 2016. Type theory in type theory using quotient inductive types.SIGPLAN Not. 51, 1 (January 2016), 18–29.

I Ambrus Kaposi, Andras Kovacs, and Thorsten Altenkirch. 2019. Constructing quotient inductive-inductivetypes. Proc. ACM Program. Lang. 3, POPL, Article 2 (January 2019), 24 pages.

I Altenkirch T., Boulier S., Kaposi A., Tabareau N. (2019) Setoid Type Theory—A Syntactic Translation. In:Hutton G. (eds) Mathematics of Program Construction. MPC 2019. Lecture Notes in Computer Science, vol11825. Springer, Cham

I Andras Kovacs, Ambrus Kaposi. Large and Infinitary Quotient Inductive-Inductive Types. Thirty-Fifth AnnualACM/IEEE Symposium on Logic in Computer Science (LICS). 8–11 July 2020

I Ambrus Kaposi, Jakob von Raumer. A Syntax for Mutual Inductive Families. To appear at the 5th InternationalConference on Formal Structures for Computation and Deduction (FSCD 2020). June 29–July 6, 2020

I Ambrus Kaposi, Andras Kovacs and Ambroise Lafont. For induction-induction, induction is enough with.Submitted to TYPES 2019 post-proceedings