22
Introduction and Motivation My Work Performance Issues Conclusion and Future Work Type Inference for a Modal Type System Yiluo Wei Supervisor: Dr Ranald Clouston The Australian National University May 24, 2019 Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 1 / 22

Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Type Inference for a Modal Type System

Yiluo Wei

Supervisor: Dr Ranald CloustonThe Australian National University

May 24, 2019

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 1 / 22

Page 2: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Schedule

1 Introduction and Motivation

2 My Work

3 Performance Issues

4 Conclusion and Future Work

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 2 / 22

Page 3: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Introduction and Motivation

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 3 / 22

Page 4: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Propositions as Types

The Curry-Howard Isomorphism

Logic side: languages for building formal proofs

Computer science side: typing disciplines from logics for solving different problems

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 4 / 22

Page 5: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Propositions as Types

A → B AB

f : A → B x : Af x : B

Intuitionistic logic

Proposition as Types

Deduction Rules as Typing Rules

Proof as Terms

· ` isZero : Int → Bool · ` 0 : Int· ` isZero 0 : Bool

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 5 / 22

Page 6: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Modal Logic and Types

Modals as operators to express modalities

The necessity modality �

�A : It is necessary that A

_A : It was possible that A

Why modal logics / modal type systems?

Widely studied and applied to types

Monads

Staged programming

Homotopy type theory

...

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22

Page 7: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Type Inference

Automatically detect the type for a term without type annotations.

λx : Int .x + 1 λx.x + 1

Why type inference?

Widely used in programming languages

More flexible, more convenient

More challenging

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 7 / 22

Page 8: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

My Work

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 8 / 22

Page 9: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Overview

A language and its interpreter written in HaskellExtend λ-calculus with modalities � and _

Add new syntax, typing and evaluation rulesMake the type system correspond to different modal logics

Intuitionistic KIntuitionistic S4Intuitionistic R

Modify the Hindley-Milner type inference algorithm so it works with my modal type system

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 9 / 22

Page 10: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

The Hindley-Milner Algorithm

Intuitively

Use a type variable to denote a unknown type

Constrain the type variables according to the syntax and known types

Solve the constraints

λf .λx.(f (x + 1)) == True

1 Let f have type a, x have type b

2 x must have type Int , so b = Int

3 Application, so f must have type a = a1 → a2, and a1 = Int

4 (f (x + 1)) has type a2, and it must have type Bool, so a2 = Bool

5 Solve them all, f : Int → Bool and x : Int

6 Therefore, the type is (Int → Bool)→ Int → Bool

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 10 / 22

Page 11: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Implementation of Intuitionistic K

Use Intuitionistic K (IK) as an exampleThe type system should be able to derive

Necessitation : if A is a theorem, then so is �A , andK : �(A → B)→ �A → �B

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 11 / 22

Page 12: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

IK - Syntax and Typing

Expr := ... | shut Expr | open Expr

Type := ... | �Type

varΓ, x : A , Γ′ ` x : A

b< Γ′

shutΓ,b ` t : A

Γ ` shut t : �A

openΓ, t : �A

Γ,b, Γ′ ` open t : Ab< Γ′

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 12 / 22

Page 13: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

IK - Derivation

shutΓ,b ` t : A

Γ ` shut t : �Aopen

Γ, t : �A

Γ,b, Γ′ ` open t : Ab< Γ′

Necessitation : if A is a theorem, then so is �A

If an expression e is well-typed in Γ = · , then so is shut e

K : �(A → B)→ �A → �B

f : �(A → B), x : �A ` shut((open f) (open x)) : �B

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 13 / 22

Page 14: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Type Inference

The HM algorithm works with the modal type systemMajor difficulties

Locks in the environment

Non-determinism in some typing rules

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 14 / 22

Page 15: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Performance Issues

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 15 / 22

Page 16: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Performance

Running time for the HM algorithm for modal type systems mostly affected by locks inthe environment

Typing rules for IS4 are non-deterministic on how to handle locks

Data structure of the environment not friendly to IR

Average running speed slower

Running times for IR and IS4 are linear to the number of locks in the environment

Time complexity does not change in the sense of big-O notation since the HMalgorithm is DEXPTIME-complete

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 16 / 22

Page 17: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Dense Locks Environment - IK vs IS4

Figure: IK vs IS4

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 17 / 22

Page 18: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Dense Locks Environment - IK vs IR

Figure: IK vs IR

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 18 / 22

Page 19: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Conclusion and Future Work

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 19 / 22

Page 20: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Conclusion

An implementation of the type system side of the Curry-Howard isomorphism forintuitionistic modal logic

The algorithmic properties, type checking and type inference, of the system

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 20 / 22

Page 21: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Future Work

More sophisticated method to deal locks in the environment

More advanced type systems, for example, with dependent types

More kinds of modalities

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 21 / 22

Page 22: Type Inference for a Modal Type System€¦ · Homotopy type theory... Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 6 / 22. Introduction and MotivationMy WorkPerformance

Introduction and Motivation My Work Performance Issues Conclusion and Future Work

Questions

Yiluo Wei ANU Type Inference for a Modal Type System May 24, 2019 22 / 22