Declarative Objects

48
Declarative Objects 7/22/10 Jonathan Edwards sdg csail MIT

description

Declarative Objects. 7/22/10 Jonathan Edwards sdg csail MIT. CMP AX,[BX] JE SKIP MOV AX,2. class Task { int start ; int end ;. class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} }. class Task { int start; - PowerPoint PPT Presentation

Transcript of Declarative Objects

Page 1: Declarative Objects

Declarative Objects

7/22/10Jonathan Edwards

sdg csail MIT

Page 2: Declarative Objects

CMP AX,[BX]JE SKIPMOV AX,2

Page 3: Declarative Objects

class Task { int start; int end;

Page 4: Declarative Objects

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} }

Page 5: Declarative Objects

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) {

Page 6: Declarative Objects

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) { start = t.end; length = length + 1; }}

Page 7: Declarative Objects

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) { start = t.end; length = length + 1; }}

Page 8: Declarative Objects

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) { length = length + 1; start = t.end; }}

Page 9: Declarative Objects

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) { int oldLength = length; start = t.end; length = oldLength + 1; }}

Page 10: Declarative Objects

class Task { int start { get {return end - length;} set {end = value + length;} } int end; int length; // start after t, increment length void slipAfter(Task t) { length = length + 1; start = t.end; }}

Page 11: Declarative Objects

?class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } void slipAfter(Task t) { int oldLength = length; start = t.end; length = oldLength + 1; }}

Page 12: Declarative Objects

Pac-Man

!

Page 13: Declarative Objects

pre-state post-state

length

startend

+ 1–get

length

startend + set

length

startend

t

thisthis

#1 #2

#3

#4

Page 14: Declarative Objects

Task = obj { start: int end: int length ::= end – start length trig { end <= start + length} slipAfter = act { t: Task start <= t.end length <= \length + 1}}

Page 15: Declarative Objects

Task = obj { start: int end: int length ::= end – start length trig { end <= start + length} slipAfter = act { t: Task start <= t.end length <= \length + 1}}

#1

#4

#3#2

Page 16: Declarative Objects

Compiler

1. \length := end – start

2. length := \length + 13. start := t.end 4. end := start + length

Page 17: Declarative Objects

what how

Declarative Programming

Compiler

Page 18: Declarative Objects

what how

Compiler

Parallel Processing

Page 19: Declarative Objects

what how

Compiler

Distributed Processing

Page 20: Declarative Objects

Pointers

Page 21: Declarative Objects

pre-state post-state

length

startend

+ 1–get

length

startend + set

length

startend

t

thisthis

Page 22: Declarative Objects

pre-state post-state

length

startend

+ 1–get

length

startend + set

length

startend

t

thisthis

t == this

Page 23: Declarative Objects

pre-state post-state

length

startend

+ 1–get

length

startend + set

length

startend

t

thisthis

t == this

Page 24: Declarative Objects

Huh?

pointers ⇒ undecidable dataflow

Compiler

Page 25: Declarative Objects

Pick two

Declarativeprogramming

Data structures

Mutablestate

CircuitsFunctions

Imperativeprogramming

Page 26: Declarative Objects

Nesting & Binding

Model-View dataflow

Page 27: Declarative Objects

Project = obj { task1: Task task2: Task }

length

startend

Task

task1task2

Project

length

startend

Task

Page 28: Declarative Objects

Project = obj { task1: Task task2: Task }

Project

length

startend

length

startend

task2

task1

Page 29: Declarative Objects

Project = obj { task1: Task task2: Task task2.start ::=> task1.end }

Project

length

startend

length

startend

task2

task1

bidirectional binding

Page 30: Declarative Objects

tasks

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Task

Page 31: Declarative Objects

tasks

length

task1startend

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Tasktask1 => tasks

cursorquantified binding

Page 32: Declarative Objects

tasks

length

task1startend

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Tasktask1 => taskstask2 => tasks

task2startend

length

Page 33: Declarative Objects

tasks

length

task1startend

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Tasktask1 => taskstask2 => taskstask2.slipAfter(task1)

task2start

+endlength

Page 34: Declarative Objects

tasks

length

task1startend

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Tasktask1 => taskstask2 => taskstask2.slipAfter(task1)

task2start

+end

length

Page 35: Declarative Objects

length

task1startend

length

startend

@5E820 task2startend

length

length

task1startend

length

startend

@5E820 task2start

+endlength

Page 36: Declarative Objects

User

Model

DB

queryupdate

getset

outputinput

View

Page 37: Declarative Objects

Model-View dataflow

internal state

external world

•outputs•getters•queries

•inputs•setters•triggers

Page 38: Declarative Objects

Model-View dataflow

internal state

external world✘

•outputs•getters•queries

•inputs•setters•triggers

Page 39: Declarative Objects

Model-View dataflow

internal state

external world

•functional•lazy

•mutating•eager

Page 40: Declarative Objects

Model-View dataflow

internal state

external world

•functional•lazy

•mutating•eager•callbacks•events

✘✘

Page 41: Declarative Objects

New rules, new patterns

• Synchronous reactive programming– Input event triggers atomic state transition– Output is pure function of new state– Asynchronicity layered on top

• Syntax order irrelevant – no control flow • Pre-state readable throughout transition• Fields can change once per transition• Actions can’t see effects of own changes

Page 42: Declarative Objects

prog { t +=> task1 t.slipAfter(task2) step \t.end ?gtr 10 t.end <= 10}

progressive binding

stepguard result of prev step

Progression

step

Page 43: Declarative Objects

length

startend

length

startend

length

startend

length

startend

+ 1+ gtr 10 10

prog

length

startend

task1 task1

task2

t t?

pre-state post-state

✘✘

Page 44: Declarative Objects

length

startend

length

startend

length

startend

length

startend

+ 1+ gtr 10 10

hyp

length

startend

task1 task1

task2

t t?

pre-state post-state

Page 45: Declarative Objects

Technical Summary• Nesting gives objects a location in global tree• Bindings propagate changes through relative

paths in tree (precise static effects)• Bindings are directed: input, output, or both– Input is change-driven, cascades eagerly– Output is lazy pure functional– Each is statically acyclic based on tree path effects– Outputs do not feedback to inputs

• Imperative islands in a declarative sea

Page 46: Declarative Objects

Pick two

Declarativeprogramming

Data structures

Mutablestate

Page 47: Declarative Objects

Declarative Objects

Declarativeprogramming

Nesting & Binding

Model-Viewdataflow

Page 48: Declarative Objects

CMP AX,[BX]JE SKIPMOV AX,2

Imperative Programming

Declarative Programming