Title: Declarative Objects
1Declarative Objects
- 7/22/10
- Jonathan Edwards
- sdg csail MIT
2CMP AX,BX JE SKIP MOV AX,2
3class Task int start int end
4class Task int start int end int length
get return end - start set end
start value
5class Task int start int end int length
get return end - start set end
start value // start after t, increment
length void slipAfter(Task t)
6class 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
7class 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
?
8class 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
?
9class 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
10class 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
11?
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
12!
Pac-Man
13t
start
end
length
3
this
this
start
start
end
get
end
set
length
1
length
1
2
4
pre-state
post-state
14Task obj start int end int
length end start length trig
end lt start length slipAfter act
t Task start lt t.end length
lt \length 1
15definition
Task obj start int end int
length end start length trig
end lt start length slipAfter act
t Task start lt t.end length
lt \length 1
data binding (getter)
triggered action (setter)
assignment
called action (method)
pre-state
16Task obj start int end int
length end start length trig
end lt start length slipAfter act
t Task start lt t.end length
lt \length 1
1 4 3 2
17- \length end start
- length \length 1
- start t.end
- end start length
Compiler
18Declarative Programming
what
how
Compiler
19Parallel Processing
what
how
Compiler
20Distributed Processing
what
how
Compiler
21Pointers
22t
start
end
length
this
this
start
start
end
get
end
set
length
1
length
pre-state
post-state
23t
start
end
length
t this
this
this
start
start
end
get
end
set
length
1
length
pre-state
post-state
24t
start
end
length
t this
this
this
start
start
end
get
end
set
length
1
length
pre-state
post-state
25pointers ? undecidable dataflow
Huh?
Compiler
26Pick two
?
Declarative programming
Circuits
Functions
?
?
Data structures
Mutable state
Imperative programming
27Nesting Binding
Model-View dataflow
28Task
start
Project
Project obj task1 Task task2 Task
end
task1
length
task2
Task
start
end
length
29Project
task1
start
Project obj task1 Task task2 Task
end
length
task2
start
end
length
30Project
task1
start
Project obj task1 Task task2 Task
task2.start gt task1.end
end
length
task2
start
end
length
bidirectional binding
31tasks
tasks dom Task
_at_3F25C
start
end
length
_at_5E820
start
end
length
32quantified binding
cursor
tasks
tasks dom Task task1 ?gt tasks
task1
start
_at_3F25C
end
start
length
end
length
_at_5E820
start
end
length
33tasks
tasks dom Task task1 ?gt tasks task2 ?gt tasks
task1
start
_at_3F25C
end
start
length
end
length
_at_5E820
task2
start
start
end
end
length
length
34tasks
tasks dom Task task1 ?gt tasks task2 ?gt
tasks task2.slipAfter(task1)
task1
start
_at_3F25C
end
start
length
end
length
_at_5E820
task2
start
start
end
end
length
length
35tasks
tasks dom Task task1 ?gt tasks task2 ?gt
tasks task2.slipAfter(task1)
task1
start
_at_3F25C
end
start
length
end
?
length
_at_5E820
task2
start
start
end
end
length
length
36task1
task1
start
start
end
end
length
length
_at_5E820
_at_5E820
task2
task2
start
start
start
start
end
end
end
end
length
length
length
length
37DB
query
update
Model
get
set
View
output
input
User
38Model-View dataflow
internal state
external world
39Model-View dataflow
internal state
?
external world
40Model-View dataflow
internal state
external world
41Model-View dataflow
internal state
- mutating
- eager
- callbacks
- events
?
?
external world
42New 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 cant see effects of own changes
43Progression
prog t gt task1 t.slipAfter(task2)
step \t.end ?gtr 10 t.end lt 10
progressive binding
step
result of prev step
guard
step
44task2
start
end
length
?
?
prog
task1
task1
t
t
?
start
start
start
start
end
end
end
end
gtr 10
10
length
length
length
length
1
?
?
pre-state
post-state
45task2
start
end
length
hyp
?
task1
task1
t
t
?
start
start
start
start
end
end
end
end
gtr 10
10
length
length
length
length
1
pre-state
post-state
46Technical 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
47Pick two
Declarative programming
Data structures
Mutable state
48Declarative Objects
Declarative programming
Nesting Binding
Model-View dataflow
49Imperative Programming
Declarative Programming
CMP AX,BX JE SKIP MOV AX,2