e cient linear types for human beings iain lane

Post on 26-Apr-2022

7 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Linear MLEfficient linear types for human beings

Iain Lane

School of Computer ScienceUniversity of Nottingham

9 July, 2011

Outline

Introduction

Linear logic

Linear ML

Demo!

Fin

Introduction

I Internship at the beginning of the year (January–April)

I Funded by Horizon project (www.horizon.ac.uk)

Project

I Work on a new programming language: Linear MLI Got some coverage on the internets

I Reddit(http://www.reddit.com/r/types/comments/g118j/linearml_is_a_pogramming_language_designed_to/)

I Ycombinator(http://news.ycombinator.com/item?id=2310587)

This talk

I Introduction to linear logic & linear type systems

I Introduction to Linear ML

I Demo, if time

Outline

Introduction

Linear logic

Linear ML

Demo!

Fin

WTF?

I First proposed by Girard in 1987 (Girard is also the inventor ofthe mustard watch)

I The connectives of linear logic have meanings in terms ofparallel and concurrent computation

I Traditional logic encourages casual use of assumptions.Duplication is free. In linear logic it is restricted via alterationsto the weakening and contraction rules

I Beginning to be used in OS research: Microsoft “Singularity”project uses linear typing for message passing

Linear logicNew connectives

I N “choose from A and B”

I ⊕ “either A or B”

I A⊗ B “both A and B”

I A ( B “A linearly implies B” or “consuming A yields B”

I !A “bang A”

Variables

Two kinds of variables

I Linear: ¿A

I Nonlinear (or sometimes “intuitionistic”): ?A

Some inference rules

both

∆ ` A ∆′ ` B

∆,∆′ ` A⊗ B⊗I

∆ ` A⊗ B ∆′, ¿A, ¿B ` C

∆,∆′ ` C⊗E

choose

∆ ` A ∆ ` B

∆ ` A N BNI

∆ ` A N B

∆ ` ANE1

∆ ` A N B

∆ ` BNE2

either

∆ ` A

∆ ` A⊕ B⊕I1

∆ ` B

∆ ` A⊕ B⊕I2

wand

∆, ¿A ` B

∆ ` A ( B( I

structural

∆ ` B

∆, ?A ` BWeakening

∆, ?A, ?A ` B

∆, ?A ` BContraction

bang

?∆ ` A

?∆ `!A!I

∆ `!A ∆′, ?A ` B

∆,∆′ ` B!E

ExampleA packet-response system

Given three types: Packet, Response and Command.

A packet can either elicit a response or issue a command

¿Packet ` Response ¿Packet ` Command

Given two distinct packets, we can produce both a responseand a command

¿Packet, ¿Packet ` Response⊗ Command

Given one packet, the server can decide whether to send aresponse or elicit a command

¿Packet ` Response N Command

Linear types?

I Variables must be used exactly once

I Enforced by going out of scope after they are used

I Useful for expressing ownership

Example

The code

w r i t e ‘ ‘ E n t e r your name : ’ ’s t r i n g name = r e a d L i n ew r i t e L i n e ( s p r i n t f ” H e l l o %s ” name )

Works just as you’d expect.

Example

BUT, the code

w r i t e ‘ ‘ E n t e r your name : ’ ’s t r i n g name = r e a d L i n ew r i t e L i n e ( s p r i n t f ” H e l l o %s ” name )w r i t e F i l e ‘ ‘ e . v . l . h a c k e r s . log ’ ’ name

Fails. Line 4: Variable ’name’ not in scope. name was consumedby the first writeLine.

Outline

Introduction

Linear logic

Linear ML

Demo!

Fin

Linear ML

I Linearly typed ‘dialect’ of ML (uses OCaml-like syntax)

I Compiled to LLVM

I Statically typed

I Strict evaluation order

Linear MLLinear types imply

I Messages passed between threads without copying

I Majority of operations performed in-place

I No need for GC

Outline

Introduction

Linear logic

Linear ML

Demo!

Fin

Outline

Introduction

Linear logic

Linear ML

Demo!

Fin

The end

https://github.com/pikatchu/LinearML

top related