. While several substructural type systems have been proposed and - - PowerPoint PPT Presentation

while several substructural type systems have been
SMART_READER_LITE
LIVE PREVIEW

. While several substructural type systems have been proposed and - - PowerPoint PPT Presentation

. . Substructural logics provide a framework for designing resource-aware type systems. . While several substructural type systems have been proposed and implemented, these either have been developed for a special purpose or have been too


slide-1
SLIDE 1

.

.

.

Substructural logics provide a framework for designing resource-aware type systems. While several substructural type systems have been proposed and implemented, these either have been developed for a special purpose or have been too unwieldy for practical use.

slide-2
SLIDE 2

Practical Affine Types

Jesse A. Tov and Riccardo Pucella

Northeastern University

January 27, 2010 .

slide-3
SLIDE 3

. .

3

slide-4
SLIDE 4

.

3

slide-5
SLIDE 5

Example: OpenGL on Android

.. .

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

  • setDebug()
  • setChooser()
  • setWrapper()

.

(Android 2.2 API Reference)

.

.

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

setDebug() setChooser() setWrapper()

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

Once the renderer is set, you can control whether the renderer draws continuously or on-demand by calling setRenderMode().

. .

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser setDebug setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode setDebug setWrapper

. . .

Typestate

4

slide-6
SLIDE 6

Example: OpenGL on Android

.. .

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

  • setDebug()
  • setChooser()
  • setWrapper()

.

(Android 2.2 API Reference)

.

.

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

setDebug() setChooser() setWrapper()

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

Once the renderer is set, you can control whether the renderer draws continuously or on-demand by calling setRenderMode().

. .

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser setDebug setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode setDebug setWrapper

. . .

Typestate

4

slide-7
SLIDE 7

Example: OpenGL on Android

.. .

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

  • setDebug()
  • setChooser()
  • setWrapper()

.

(Android 2.2 API Reference)

.

.

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

setDebug() setChooser() setWrapper()

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

Once the renderer is set, you can control whether the renderer draws continuously or on-demand by calling setRenderMode().

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode setDebug setWrapper

. . .

Typestate

4

slide-8
SLIDE 8

Example: OpenGL on Android

.

.

.

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

setDebug() setChooser() setWrapper()

.

(Android 2.2 API Reference)

.

.

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

  • setDebug()
  • setChooser()
  • setWrapper()

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

Once the renderer is set, you can control whether the renderer draws continuously or on-demand by calling setRenderMode().

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode setDebug, setWrapper

. . .

Typestate

4

slide-9
SLIDE 9

Example: OpenGL on Android

.

.

.

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

setDebug() setChooser() setWrapper()

.

(Android 2.2 API Reference)

.

.

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

  • setDebug()
  • setChooser()
  • setWrapper()

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

Once the renderer is set, you can control whether the renderer draws continuously or on-demand by calling setRenderMode().

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode, setDebug, setWrapper

. . .

Typestate

4

slide-10
SLIDE 10

Example: OpenGL on Android

.. .

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

  • setDebug()
  • setChooser()
  • setWrapper()

.

(Android 2.2 API Reference)

.

.

All you have to do to initialize a GLSurfaceView is call setRenderer(). However, if desired, you can modify the default behavior of GLSurfaceView by calling one or more of these methods before setRenderer:

setDebug() setChooser() setWrapper()

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

You can optionally modify the behavior of GLSurfaceView by calling one or more of the debugging methods setDe-

bug(), and setWrapper(). These methods may be called be-

fore and/or after setRenderer, …

.

.

Once the renderer is set, you can control whether the renderer draws continuously or on-demand by calling setRenderMode().

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode, setDebug, setWrapper

. . .

Typestate

4

slide-11
SLIDE 11

Stateful Programming

. .

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode, setDebug, setWrapper

.

.

.

Initial

.

.

Error

.

.

Initialized

.

.

DataSourceConfigured

.

.

Prepared

.

.

Recording

.

.

Released

.

error

.

reset()

.

setAudioSource(), setVideoSource()

.

r e l e a s e ( )

.

setAudioSource(), setVideoSource()

.

reset()

.

setOutputFormat()

.

reset()

.

setAudioEncoder(), setVideoEncoder(), setOutputFile(), setVideoSize(), setVideoFrameRate(), setPreviewDisplay()

.

prepare()

.

r e s e t ( )

.

start()

.

reset(), stop()

.

.

.

.

.

.

.

.

.

.

.

. vertex float list . vertex .vertex list . (vertex process) list .. .

The malloc(), calloc(), valloc(), realloc(), and reallocf() functions allocate memory. The free() function frees al- locations that were created via the preceding allocation functions. .

.

connection established

.

.

server greeting

.

.

not authenticated

.

.

authenticated

.

.

selected

.

.

logout

.

.

connection closed

5

slide-12
SLIDE 12

Stateful Programming

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode, setDebug, setWrapper

. .

.

.

Initial

.

.

Error

.

.

Initialized

.

.

DataSourceConfigured

.

.

Prepared

.

.

Recording

.

.

Released

.

error

.

reset()

.

setAudioSource(), setVideoSource()

.

r e l e a s e ( )

.

setAudioSource(), setVideoSource()

.

reset()

.

setOutputFormat()

.

reset()

.

setAudioEncoder(), setVideoEncoder(), setOutputFile(), setVideoSize(), setVideoFrameRate(), setPreviewDisplay()

.

prepare()

.

r e s e t ( )

.

start()

.

reset(), stop()

.

.

.

.

.

.

.

.

.

.

.

. vertex float list . vertex .vertex list . (vertex process) list .. .

The malloc(), calloc(), valloc(), realloc(), and reallocf() functions allocate memory. The free() function frees al- locations that were created via the preceding allocation functions. .

.

connection established

.

.

server greeting

.

.

not authenticated

.

.

authenticated

.

.

selected

.

.

logout

.

.

connection closed

5

slide-13
SLIDE 13

Stateful Programming

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode, setDebug, setWrapper

.

.

.

Initial

.

.

Error

.

.

Initialized

.

.

DataSourceConfigured

.

.

Prepared

.

.

Recording

.

.

Released

.

error

.

reset()

.

setAudioSource(), setVideoSource()

.

r e l e a s e ( )

.

setAudioSource(), setVideoSource()

.

reset()

.

setOutputFormat()

.

reset()

.

setAudioEncoder(), setVideoEncoder(), setOutputFile(), setVideoSize(), setVideoFrameRate(), setPreviewDisplay()

.

prepare()

.

r e s e t ( )

.

start()

.

reset(), stop()

.

.

.

.

.

.

.

.

.

.

.

.

.

(vertex × float) list

. vertex .vertex list . (vertex × process) list .

ε

.

ε

.

ε

.

.

The malloc(), calloc(), valloc(), realloc(), and reallocf() functions allocate memory. The free() function frees al- locations that were created via the preceding allocation functions. .

.

connection established

.

.

server greeting

.

.

not authenticated

.

.

authenticated

.

.

selected

.

.

logout

.

.

connection closed

5

slide-14
SLIDE 14

Stateful Programming

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode, setDebug, setWrapper

.

.

.

Initial

.

.

Error

.

.

Initialized

.

.

DataSourceConfigured

.

.

Prepared

.

.

Recording

.

.

Released

.

error

.

reset()

.

setAudioSource(), setVideoSource()

.

r e l e a s e ( )

.

setAudioSource(), setVideoSource()

.

reset()

.

setOutputFormat()

.

reset()

.

setAudioEncoder(), setVideoEncoder(), setOutputFile(), setVideoSize(), setVideoFrameRate(), setPreviewDisplay()

.

prepare()

.

r e s e t ( )

.

start()

.

reset(), stop()

.

.

.

.

.

.

.

.

.

.

.

.

(vertex × float) list

. vertex .vertex list . (vertex × process) list .

ε

.

ε

.

ε

.. .

The malloc(), calloc(), valloc(), realloc(), and reallocf() functions allocate memory. The free() function frees al- locations that were created via the preceding allocation functions. .

.

connection established

.

.

server greeting

.

.

not authenticated

.

.

authenticated

.

.

selected

.

.

logout

.

.

connection closed

5

slide-15
SLIDE 15

Stateful Programming

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode, setDebug, setWrapper

.

.

.

Initial

.

.

Error

.

.

Initialized

.

.

DataSourceConfigured

.

.

Prepared

.

.

Recording

.

.

Released

.

error

.

reset()

.

setAudioSource(), setVideoSource()

.

r e l e a s e ( )

.

setAudioSource(), setVideoSource()

.

reset()

.

setOutputFormat()

.

reset()

.

setAudioEncoder(), setVideoEncoder(), setOutputFile(), setVideoSize(), setVideoFrameRate(), setPreviewDisplay()

.

prepare()

.

r e s e t ( )

.

start()

.

reset(), stop()

.

.

.

.

.

.

.

.

.

.

.

.

(vertex × float) list

. vertex .vertex list . (vertex × process) list .

ε

.

ε

.

ε

.

.

The malloc(), calloc(), valloc(), realloc(), and reallocf() functions allocate memory. The free() function frees al- locations that were created via the preceding allocation functions.

.

.

.

connection established

.

.

server greeting

.

.

not authenticated

.

.

authenticated

.

.

selected

.

.

logout

.

.

connection closed

5

slide-16
SLIDE 16

Stateful Programming

.

.

. raw

.

. ready .

new GLSurfaceView

.

setChooser, setDebug, setWrapper

.

setRenderer

.

rendering operations

.

setRenderMode, setDebug, setWrapper

.

.

.

Initial

.

.

Error

.

.

Initialized

.

.

DataSourceConfigured

.

.

Prepared

.

.

Recording

.

.

Released

.

error

.

reset()

.

setAudioSource(), setVideoSource()

.

r e l e a s e ( )

.

setAudioSource(), setVideoSource()

.

reset()

.

setOutputFormat()

.

reset()

.

setAudioEncoder(), setVideoEncoder(), setOutputFile(), setVideoSize(), setVideoFrameRate(), setPreviewDisplay()

.

prepare()

.

r e s e t ( )

.

start()

.

reset(), stop()

.

.

.

.

.

.

.

.

.

.

.

.

(vertex × float) list

. vertex .vertex list . (vertex × process) list .

ε

.

ε

.

ε

.

.

The malloc(), calloc(), valloc(), realloc(), and reallocf() functions allocate memory. The free() function frees al- locations that were created via the preceding allocation functions. .

.

connection established

.

.

server greeting

.

.

not authenticated

.

.

authenticated

.

.

selected

.

.

logout

.

.

connection closed

.

5

slide-17
SLIDE 17

. Theoretical . Practical . Special Resources . General Resources

.

.

ILL

.

.

URAL

.

.

session types calculi

.

.

region calculi

.

.

Sing#

.

.

Vault

.

.

Cyclone

.

.

Alms

.

?

.

(Fluet 2007; Pucella and Heller 2008)

6

slide-18
SLIDE 18

. Theoretical . Practical . Special Resources . General Resources

.

.

ILL

.

. λURAL

.

.

session types calculi

.

.

region calculi

.

.

Sing#

.

.

Vault

.

.

Cyclone

.

.

Alms

.

?

.

(Fluet 2007; Pucella and Heller 2008)

6

slide-19
SLIDE 19

. Theoretical . Practical . Special Resources . General Resources

.

.

ILL

.

. λURAL

.

.

session types calculi

.

.

region calculi

.

.

Sing#

.

.

Vault

.

.

Cyclone

.

.

Alms

.

?

.

(Fluet 2007; Pucella and Heller 2008)

6

slide-20
SLIDE 20

. Theoretical . Practical . Special Resources . General Resources

.

.

ILL

.

. λURAL

.

.

session types calculi

.

.

region calculi

.

.

Sing#

.

.

Vault

.

.

Cyclone

.

.

Alms

.

?

.

(Fluet 2007; Pucella and Heller 2008)

6

slide-21
SLIDE 21

. Theoretical . Practical . Special Resources . General Resources

.

.

ILL

.

. λURAL

.

.

session types calculi

.

.

region calculi

.

.

Sing#

.

.

Vault

.

.

Cyclone

.

.

Alms

.

?

.

(Fluet 2007; Pucella and Heller 2008)

6

slide-22
SLIDE 22

What We’ve Done

A language design (like Ocaml, but with affine types) A prototype implementation (with libraries and examples) A core model (with nice theorems)

7

slide-23
SLIDE 23

What We’ve Done

A language design (like Ocaml, but with affine types) A prototype implementation (with libraries and examples) A core model (with nice theorems)

7

slide-24
SLIDE 24

Alms by Example

slide-25
SLIDE 25

OpenGL in Alms

module PrimGLSurface : sig type glSurface val create

: unit → glSurface

val setChooser : glSurface → unit val setRenderer : glSurface → unit val setMode

: glSurface → unit

val setDebug

: glSurface → unit

end

9

slide-26
SLIDE 26

An OpenGL Client

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in . raw setChooser surface; raw . setRenderer surface; raw. ready . setMode surface; ready setDebug surface; ready surface .

10

slide-27
SLIDE 27

An OpenGL Client

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) setChooser surface;

(∗ raw ∗)

. setRenderer surface;

(∗ raw.

ready ∗) . setMode surface;

(∗ ready ∗)

setDebug surface;

(∗ ready ∗)

surface .

10

slide-28
SLIDE 28

An OpenGL Client

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) setChooser surface;

(∗ raw ∗)

. setMode surface;

(∗ ready? ∗)

. setRenderer surface;

(∗ raw.

ready ∗) setDebug surface;

(∗ ready ∗)

surface .

10

slide-29
SLIDE 29

OpenGL in Alms: Take 2

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

module type GL SURFACE = sig type raw type ready type β glSurface val create

: unit → raw glSurface

val setChooser : raw glSurface → unit val setRenderer : raw glSurface → ready glSurface val setMode

: ready glSurface → unit

val setDebug

:

A

β. β glSurface → unit

end

11

slide-30
SLIDE 30

An OpenGL Client: Take 2

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) setChooser surface;

(∗ ready ∗)

. let surface = setRenderer surface in

(∗ raw.

ready ∗) . setMode surface;

(∗ ready ∗)

setDebug surface;

(∗ ready ∗)

surface .

Type error at <opengl.alms> (line 4, columns 13-20): In application, operand type not in operator’s domain: actual: raw glSurface expected: ready glSurface

12

slide-31
SLIDE 31

An OpenGL Client: Take 2

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) setChooser surface;

(∗ ready ∗)

. setMode surface in

(∗ ready? ∗)

. let surface = setRenderer surface;

(∗ raw.

ready ∗) setDebug surface;

(∗ ready ∗)

surface .

Type error at <opengl.alms> (line 4, columns 13-20): In application, operand type not in operator’s domain: actual: raw glSurface expected: ready glSurface

12

slide-32
SLIDE 32

An OpenGL Client: Take 2

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) . setChooser surface;

(∗ raw ∗)

. let surface = setRenderer surface in

(∗ raw.

ready ∗) setMode surface;

(∗ ready ∗)

setDebug surface;

(∗ ready ∗)

surface .

Type error at <opengl.alms> (line 4, columns 16-23): In application, operand type not in operator’s domain: actual: ready glSurface expected: raw glSurface

13

slide-33
SLIDE 33

An OpenGL Client: Take 2

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) . let surface = setRenderer surface;

(∗ raw.

ready ∗) . setChooser surface in

(∗ raw? ∗)

setMode surface;

(∗ ready ∗)

setDebug surface;

(∗ ready ∗)

surface .

Type error at <opengl.alms> (line 4, columns 16-23): In application, operand type not in operator’s domain: actual: ready glSurface expected: raw glSurface

13

slide-34
SLIDE 34

An OpenGL Client: Take 2

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) . let surface′ = setRenderer surface;

(∗ raw.

ready′ ∗) . setChooser surface in

(∗ raw ∗)

setMode surface′;

(∗ ready′ ∗)

setDebug surface′;

(∗ ready′ ∗)

surface′ .

Type error at <opengl.alms> (line 4, columns 16-23): In application, operand type not in operator’s domain: actual: ready glSurface expected: raw glSurface

13

slide-35
SLIDE 35

OpenGL in Alms: Take 3

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

module type GL SURFACE = sig type raw type ready type β glSurface : A val create

: unit → raw glSurface

val setChooser : raw glSurface → raw glSurface val setRenderer : raw glSurface → ready glSurface val setMode

: ready glSurface → ready glSurface

val setDebug

:

A

β. β glSurface → β glSurface

end

14

slide-36
SLIDE 36

An OpenGL Client: Take 3

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) . let surface = setChooser surface in

(∗ raw ∗)

. let surface = setRenderer surface in

(∗ raw.

ready ∗) let surface = setMode surface in

(∗ ready ∗)

let surface = setDebug surface in

(∗ ready ∗)

surface .

Type error at <opengl.alms> (line 2, col. 7 to line 7, col. 12): Affine variable ‘surface’ of type ‘raw glSurface’ duplicated in match or let.

15

slide-37
SLIDE 37

An OpenGL Client: Take 3

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) . let surface′= setRenderer surface in

(∗ raw.

ready′ ∗) . let

= setChooser surface in (∗ raw ∗)

let surface = setMode surface′ in

(∗ ready′.

ready ∗) let surface = setDebug surface in

(∗ ready ∗)

surface .

Type error at <opengl.alms> (line 2, col. 7 to line 7, col. 12): Affine variable ‘surface’ of type ‘raw glSurface’ duplicated in match or let.

15

slide-38
SLIDE 38

An OpenGL Client: Take 3

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) . let surface′= setRenderer surface in

(∗ raw.

ready′ ∗) . let

= setChooser surface in (∗ raw ∗)

let surface = setMode surface′ in

(∗ ready′.

ready ∗) let surface = setDebug surface in

(∗ ready ∗)

surface .

Type error at <opengl.alms> (line 2, col. 7 to line 7, col. 12): Affine variable ‘surface’ of type ‘raw glSurface’ duplicated in match or let.

15

slide-39
SLIDE 39

An OpenGL Client: Take 3

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) . let surface = setChooser surface in

(∗ raw ∗)

. let surface = setRenderer surface in

(∗ raw.

ready ∗) let surface = setMode surface in

(∗ ready ∗)

let surface = setDebug surface in

(∗ ready ∗)

surface .

Type error at <opengl.alms> (line 2, col. 7 to line 7, col. 12): Affine variable ‘surface’ of type ‘raw glSurface’ duplicated in match or let.

15

slide-40
SLIDE 40

An OpenGL Client: Take 3

. . .

..

ready

.

setDebug(), setMode()

.

.

raw

.

setDebug(), setChooser()

.

setRenderer()

.

create()

let newSurface () = let surface = create () in

(∗ .

raw ∗) setChooser surface;

(∗ raw ∗)

setRenderer surface;

(∗ raw.

ready ∗) setMode surface;

(∗ ready ∗)

setDebug surface

(∗ ready ∗)

15

slide-41
SLIDE 41

OpenGL Implementation

module GLSurface : GL SURFACE = struct type raw

= unit

type ready

= unit

type β glSurface = PrimGLSurface.glSurface

· · ·

end . . .

module type GL SURFACE = sig type raw type ready type β glSurface : A val create : unit → raw glSurface val setChooser : raw glSurface → raw glSurface val setRenderer : raw glSurface → ready glSurface val setMode : ready glSurface → ready glSurface val setDebug : β glSurface → β glSurface end 16

slide-42
SLIDE 42

OpenGL Implementation

module GLSurface : GL SURFACE = struct type raw

= unit

type ready

= unit

type β glSurface = PrimGLSurface.glSurface

· · ·

end . . .

PrimGLSurface.glSurface : U

β glSurface : A . U ⊑ A . . .

module type GL SURFACE = sig type raw type ready type β glSurface : A val create : unit → raw glSurface val setChooser : raw glSurface → raw glSurface val setRenderer : raw glSurface → ready glSurface val setMode : ready glSurface → ready glSurface val setDebug : β glSurface → β glSurface end 16

slide-43
SLIDE 43

OpenGL Implementation

module GLSurface : GL SURFACE = struct type raw

= unit

type ready

= unit

type β glSurface = PrimGLSurface.glSurface let create = PrimGLSurface.create let setRenderer (surface: raw glSurface) = PrimGLSurface.setRenderer surface; surface

· · ·

end . . .

module type GL SURFACE = sig type raw type ready type β glSurface : A val create : unit → raw glSurface val setChooser : raw glSurface → raw glSurface val setRenderer : raw glSurface → ready glSurface val setMode : ready glSurface → ready glSurface val setDebug : β glSurface → β glSurface end 16

slide-44
SLIDE 44

More Examples

Typestate Socket.accept : α socket → α listening →

(∃β. β socket × β ready) × α listening

Session types Session.send : (!ˆ

α; β) channel → ˆ α A − → β channel

Regions (with adoption/focus) Rgn.adopt : (γ,ˆ

α) rgn → (δ,ˆ α) rgn1 A − → δ ptr A − → γ ptr × (γ,ˆ α) rgn

Strong updates Ref.swap : ˆ

α aref → ˆ β

A

− → ˆ β aref × ˆ α

Fractional capabilities Fractional.split : (β,γ) cap → (β,γ/2) cap × (β,γ/2) cap

17

slide-45
SLIDE 45

Design Rationale

slide-46
SLIDE 46

The Exponential

Linear Logic (Girard 1987):

. . , !B, !B . . . . , !B . . . (Contraction)

19

slide-47
SLIDE 47

The Problem

Ocaml:

λf (x,y) → f x y : (α → β → γ) → α × β → γ

ILL (Bierman 1993): f promote f for g in p let derelict p be x y in derelict derelict g x y f p let derelict p be x y in derelict f x y

20

slide-48
SLIDE 48

The Problem

Ocaml:

λf (x,y) → f x y : (α → β → γ) → α × β → γ

ILL (Bierman 1993):

λf → promote f for g in λp → let derelict p be x ⊗ y

in derelict (derelict g x) y

: !(α ⊸ !(β ⊸ γ)) ⊸ !(!(α ⊗ β) ⊸ γ) λf p → let derelict p be x ⊗ y

in derelict (f x) y

: (α ⊸ !(β ⊸ γ)) ⊸ !(α ⊗ β) ⊸ γ

20

slide-49
SLIDE 49

The Problem

Ocaml:

λf (x,y) → f x y : (α → β → γ) → α × β → γ

ILL to Alms:

λf → promote f for g in λp → let derelict p be x ⊗ y

in derelict (derelict g x) y

: (α → β → γ) A − → α × β → γ λf p → let derelict p be x ⊗ y

in derelict (f x) y

: (α A − → β → γ) A − → α × β

A

− → γ

20

slide-50
SLIDE 50

The Problem

Ocaml:

λf (x,y) → f x y : (α → β → γ) → α × β → γ

ILL to Alms:

λf (x,y) → f x y : (α → β → γ) → α × β → γ λf (x,y) → f x y : (α A − → β → γ) → α × β

A

− → γ

20

slide-51
SLIDE 51

The Problem

Ocaml:

λf (x,y) → f x y : (α → β → γ) → α × β → γ

Alms:

λf (x,y) → f x y : (α δ − → β → γ) → α × β δ − → γ

f x y f x y

A A 20

slide-52
SLIDE 52

Dereliction Subtyping

workerThread : unit U

− → unit

Thread.fork

: (unit A − → unit) U − → thread

unit U unit unit A unit (U A) workerThread unit A unit Thread.fork workerThread thread

21

slide-53
SLIDE 53

Dereliction Subtyping

workerThread : unit U

− → unit

Thread.fork

: (unit A − → unit) U − → thread

unit U

− → unit ≤

unit A

− → unit

(U ⊑ A) workerThread : unit A

− → unit

Thread.fork workerThread : thread

21

slide-54
SLIDE 54

Principal Promotion

λx → x : α U − → α λf x → f x : (α1

γ

− → α2) U − → α1

γ

− → α2 λf g x → f (g x) : (α2

γ

− → α3) U − → (α1

δ

− → α2) γ − → α1

γ⊔δ

− − → α3

.

.

.

  • Theorem. Alms’s type system finds the type

with least kind for every typable function.

22

slide-55
SLIDE 55

Principal Promotion

λx → x : α U − → α λf x → f x : (α1

γ

− → α2) U − → α1

γ

− → α2 λf g x → f (g x) : (α2

γ

− → α3) U − → (α1

δ

− → α2) γ − → α1

γ⊔δ

− − → α3

.

.

.

  • Theorem. Alms’s type system finds the type

with least kind for every typable function.

22

slide-56
SLIDE 56

Usage Kinds

type α list = Nil | Cons of α × α list let rec foldr f z xs = match xs with | Cons(x, xs) → f x (foldr f z xs) | Nil

→ z

int list U raw glSurface list A raw glSurface ref

23

slide-57
SLIDE 57

Usage Kinds

type α list = Nil | Cons of α × α list let rec foldr f z xs = match xs with | Cons(x, xs) → f x (foldr f z xs) | Nil

→ z

int list

: U

raw glSurface list : A raw glSurface ref

23

slide-58
SLIDE 58

Usage Kinds

type α list = Nil | Cons of α × α list let rec foldr f z xs = match xs with | Cons(x, xs) → f x (foldr f z xs) | Nil

→ z

int list

: U

raw glSurface list : A raw glSurface ref : ?

23

slide-59
SLIDE 59

Usage Kinds

type α list = Nil | Cons of α × α list let rec foldr f z xs = match xs with | Cons(x, xs) → f x (foldr f z xs) | Nil

→ z

int list

: U

raw glSurface list : A raw glSurface ref : ?

23

slide-60
SLIDE 60

Usage Kinds

type (α:U) list = Nil | Cons of α × α list

listU U U

let rec foldr f z xs = match xs with | Cons(x, xs) → f x (foldr f z xs) | Nil

→ z

type A listA NilA | ConsA of listA

listA A A

let rec foldrA f z xs match xs with | ConsA x xs f x foldrA f z xs | NilA z

23

slide-61
SLIDE 61

Usage Kinds

type (α:U) listU = NilU | ConsU of α × α list (∗ listU : U ⇒ U ∗) let rec foldrU f z xs = match xs with | ConsU(x, xs) → f x (foldrU f z xs) | NilU

→ z

type A listA NilA | ConsA of listA

listA A A

let rec foldrA f z xs match xs with | ConsA x xs f x foldrA f z xs | NilA z

23

slide-62
SLIDE 62

Usage Kinds

type (α:U) listU = NilU | ConsU of α × α list (∗ listU : U ⇒ U ∗) let rec foldrU f z xs = match xs with | ConsU(x, xs) → f x (foldrU f z xs) | NilU

→ z

type (α:A) listA = NilA | ConsA of α × α listA (∗ listA : A ⇒ A ∗) let rec foldrA f z xs = match xs with | ConsA(x, xs) → f x (foldrA f z xs) | NilA

→ z

23

slide-63
SLIDE 63

Dependent Usage Kinds

type α list = Nil | Cons of α × α list (∗ list : Πα. ⟨α⟩ ∗) let rec foldr f z xs = match xs with | Cons(x,xs) → f x (foldr f z xs) | Nil

→ z

23

slide-64
SLIDE 64

Dependent Usage Kinds

type α list = Nil | Cons of α × α list (∗ list : Πα. ⟨α⟩ ∗) let rec foldr f z xs = match xs with | Cons(x,xs) → f x (foldr f z xs) | Nil

→ z

. . .

(×) : Πα. Πβ. ⟨α⟩ ⊔ ⟨β⟩ (+) : Πα. Πβ. ⟨α⟩ ⊔ ⟨β⟩

ref

: Πα. U

glSurface :

Πα. A

23

slide-65
SLIDE 65

Conclusion

slide-66
SLIDE 66

Related Work

λURAL (Ahmed et al. 2005)

“Uniqueness Typing Simplified” (de Vries et al. 2008) System F (Mazurak et al. 2010) Fine (Swamy et al. 2010) Plaid (Aldrich et al. 2009)

25

slide-67
SLIDE 67

Related Work

λURAL (Ahmed et al. 2005)

“Uniqueness Typing Simplified” (de Vries et al. 2008) System F◦ (Mazurak et al. 2010) Fine (Swamy et al. 2010) Plaid (Aldrich et al. 2009)

25

slide-68
SLIDE 68

Alms: Practical Affine Types

Affine types:

  • are for revocation
  • generalize other resource-aware type systems
  • don’t have to be weird or difficult

Paper: more examples and our model Online: prototype implementation and extended paper

26

slide-69
SLIDE 69

Thank You

Affine types:

  • are for revocation
  • generalize other resource-aware type systems
  • don’t have to be weird or difficult

Paper: more examples and our model Online: prototype implementation and extended paper

26

slide-70
SLIDE 70

This frame intentionally left blank.

27

slide-71
SLIDE 71

Why Affine Types?

Control.

. E[callcc v] −

→ .

E[v (λx.abort . E[x])] .

28

slide-72
SLIDE 72

Why Affine Types?

Control.

. E[callcc v] −

→ .

E[v (λx.abort . E[x])] .

28

slide-73
SLIDE 73

Why Affine Types?

Control.

E[C v] −

→ v (λx. abort E[x])

. E abort e e.

28

slide-74
SLIDE 74

Why Affine Types?

Control.

E[C v] −

→ v (λx. abort E[x])

. E[abort e] −

→ e.

.

28