bidirectional programming
play

Bidirectional Programming Nate Foster Cornell University CS 2110 - PowerPoint PPT Presentation

Bidirectional Programming Nate Foster Cornell University CS 2110 24 November 2015 Languages


  1. Bidirectional Programming Nate Foster Cornell University CS 2110 24 November 2015 Languages                                                                                                  

  2. Most programming languages, like C...

  3. Java,

  4. Python,

  5. and C++ are general purpose.

  6. I’m interested in designing languages that are specifjcally designed for particular tasks

  7. Domain-specifjc languages 3 • Clean semantics • Natural syntax • Better tools

  8. The View Update Problem In databases, this is known as the view update problem. [Bancilhon, Spryatos ’81] 6 View Database Query A B C x 1 true y 2 true z 3 false A B C x 1 false y 100 true Trigger

  9. The View Update Problem In Practice It also arises in data converters and synchronizers... [Foster, Greenwald, Pierce, Schmitt JCSS ’07] — Harmony 6 Common target Replica in format A format Replica in format B Synchronized replica in Synchronized replica in format B format A

  10. The View Update Problem In Practice ...in picklers and unpicklers... [Fisher, Gruber ’05] — PADS 6 In-memory representation Binary file application update Updated binary file

  11. The View Update Problem In Practice ...in model-driven software development... [Stevens ’07] — bidirectional model transformations 6 Java code UML model Point x : int y : int translate(int x,int y) refactor Point x : int y : int translate(int x, int y) moveTo(int x, int y) Updated Java code Refactored model

  12. Problem How do we write these bidirectional transformations? 7

  13. Problem: Why is it hard? We want updates to the view to be translated “exactly”... 7

  14. Problem: Why is it hard? We want updates to the view to be translated “exactly”... 7

  15. Problem: Why is it hard? ...but some updates have many corresponding source up- dates... 7 ?

  16. Problem: Why is it hard? ...while others have none ! 7 ?

  17. Possible Approaches Bad: write the two transformations as separate functions. 8 • tedious to program • diffjcult to get right • a nightmare to maintain

  18. Possible Approaches Good: derive both transformations from the same pro- gram. design 8 • Clean semantics: behavioral laws guide language • Natural syntax: parsimonious and compositional • Better tools: type system guarantees well-behavedness

  19. “Bidirectional languages are an effective and elegant means of describing updatable views”

  20. [Foster, Greenwald, Moore, Pierce, Schmitt TOPLAS ’07] Lenses ’‘Never look back unless you are planning to go that way” —H D Thoreau

  21. Terminology 11 get

  22. Terminology 11 put

  23. Terminology 11 lens

  24. Bidirectional vs. Bijective If get is non-injective, put needs access to the original source. Of course, the purely bijective case is also interesting. 12 non-injective function

  25. The Bijective Case For bijective transformations... ...the desired behavior is obvious. 13 T S

  26. The General Case But for bidirectional transformations... ... we need to identify conditions that allow us to 14 T S • recognize and reject bad (unreasonable) programs • understand and predict behavior

  27. An Unreasonable Example 15 project out string component foo 0 foo

  28. An Unreasonable Example 15 foo 0 foo bar

  29. 15 An Unreasonable Example foo 0 foo blech 5 bar return a constant

  30. An Unreasonable Example 15 foo 0 foo blech 5 bar ≠ blech

  31. The PutGet law Principle: Updates should be “translated exactly” — i.e., to a target. Formally: v 16 source for which get yields exactly the updated get ( put v s ) =

  32. 17 A Debatable Example project out and duplicate string component foo 0 foo foo

  33. A Debatable Example 17 foo 0 foo foo bar foo

  34. A Debatable Example 17 foo 0 foo foo bar 0 bar foo propagate "newest" string

  35. A Debatable Example 17 foo 0 foo foo bar 0 bar foo ≠ bar bar

  36. Another Unreasonable Example 18 project out string component foo 5 foo

  37. Another Unreasonable Example 18 foo 5 foo bar

  38. 18 Another Unreasonable Example foo 5 foo bar 0 bar propagate always set numeric updated string field to 0

  39. 18 Another Unreasonable Example foo 5 foo = foo

  40. 18 Another Unreasonable Example foo 5 foo = ≠ foo 0 foo

  41. The GetPut law Principle: If the view does not change, neither should the source. Formally: s 19 put ( get s ) s =

  42. Another Debatable Example 20 project out string component foo 0 foo

  43. Another Debatable Example 20 foo 0 foo bar

  44. 20 Another Debatable Example foo 0 foo bar 1 bar increment numeric component if string component has changed

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend