1 / 48

Declarative Objects

Explore the fundamentals of declarative programming with pointers in compiler design. Learn the concepts of parallel and distributed processing, along with nesting and binding of mutable state. Dive into data structures, functions, circuits, and model-view dataflow in a declarative paradigm.

geraldt
Télécharger la présentation

Declarative Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Declarative Objects 7/22/10 Jonathan Edwards sdg csail MIT

  2. CMP AX,[BX] JE SKIP MOV AX,2

  3. class Task { int start; int end;

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

  5. 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) {

  6. 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; } }

  7. 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; } } ✘

  8. 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; } } ✘

  9. 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; }}

  10. 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; } }

  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

  13. t start end length #3 this this start start set get – end end + length + 1 length #1 #2 #4 pre-state post-state

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

  15. 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

  16. \length := end – start length := \length + 1 start := t.end end := start + length Compiler

  17. Declarative Programming what how Compiler

  18. Parallel Processing what how Compiler

  19. Distributed Processing what how Compiler

  20. Pointers

  21. t start end length this this start start set get – end end + length + 1 length pre-state post-state

  22. t start end length t == this this this start start set get – end end + length + 1 length pre-state post-state

  23. t start end length t == this this this start start set get – end end + length + 1 length pre-state post-state

  24. pointers ⇒ undecidable dataflow Huh? Compiler

  25. Pick two ✘ Declarative programming Functions Circuits ✘ ✘ Data structures Imperative programming Mutable state

  26. Nesting & Binding Model-View dataflow

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

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

  29. Project task1 start Project =obj { task1: Task task2: Task task2.start ::=> task1.end } end length task2 start end length bidirectional binding

  30. tasks:dom Task tasks @3F25C start end length @5E820 start end length

  31. quantified binding cursor tasks:dom Task task1 => tasks tasks task1 @3F25C start end start length end length @5E820 start end length

  32. tasks:dom Task task1 => tasks task2 => tasks tasks task1 @3F25C start end start length end length @5E820 task2 start start end end length length

  33. tasks:dom Task task1 => tasks task2 => tasks task2.slipAfter(task1) tasks task1 @3F25C start end start length end length @5E820 task2 start start end end + length length

  34. tasks:dom Task task1 => tasks task2 => tasks task2.slipAfter(task1) tasks task1 @3F25C start end start length end ✘ length @5E820 task2 start start end end + length length

  35. task1 task1 start start end end length length @5E820 task2 @5E820 task2 start start start start end end + end end length length length length

  36. DB update query Model get set View input output User

  37. Model-View dataflow internal state • inputs • setters • triggers • outputs • getters • queries external world

  38. Model-View dataflow internal state • inputs • setters • triggers • outputs • getters • queries ✘ external world

  39. Model-View dataflow internal state • mutating • eager • functional • lazy external world

  40. Model-View dataflow internal state • mutating • eager • callbacks • events • functional • lazy ✘ ✘ external world

  41. 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

  42. Progression prog { t +=> task1 t.slipAfter(task2) step \t.end ?gtr 10 t.end <= 10 } progressive binding step result of prev step guard step

  43. task2 start end length ✘ ✘ prog task1 t t task1 ? start start start start end + end gtr 10 10 end end length + 1 length length length ✘ ✘ pre-state post-state

  44. task2 start end length hyp ✘ task1 t t task1 ? start start start start end + end gtr 10 10 end end length + 1 length length length pre-state post-state

  45. 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

  46. Pick two Declarative programming Data structures Mutable state

  47. Declarative Objects Declarative programming Nesting & Binding Model-View dataflow

  48. Imperative Programming Declarative Programming CMP AX,[BX] JE SKIP MOV AX,2

More Related