matching lenses
play

Matching Lenses Davi M. J. Barbosa (Polytechnique) Julien Cretin - PowerPoint PPT Presentation

Matching Lenses Davi M. J. Barbosa (Polytechnique) Julien Cretin (Polytechnique/INRIA) Nate Foster (Cornell) Michael Greenberg (Penn) Benjamin C. Pierce (Penn) ICFP 10 Example =History (5 pts)= List the inventors of the following


  1. Matching Lenses Davi M. J. Barbosa (Polytechnique) Julien Cretin (Polytechnique/INRIA) Nate Foster (Cornell) Michael Greenberg (Penn) Benjamin C. Pierce (Penn) ICFP ’10

  2. Example =History (5 pts)= List the inventors of the following programming languages. * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *) =Scoping (2 pts)= Which of these terms are closed? * ń x. ń y.x (* Yes *) * ( ń x. ń z.x) ń x. ń y.z (* No *) =Lambda Calculus (3 pts)= Give a weakly normalizing term which is not strongly normalizing. (* ( ń x. ń y.y) (( ń x.x x) ń x.x x) *)

  3. Example =History (5 pts)= =History= List the inventors of the List the inventors of the following programming languages. following programming languages. * Haskell 98 (* Hudak,PJ,Wadler *) * Haskell 98 * LISP 58 (* McCarthy *) * LISP 58 * ML 73 (* Gordon,Milner *) * ML 73 =Scoping (2 pts)= =Scoping= Which of these terms are closed? Which of these terms are closed? * ń x. ń y.x * ń x. ń y.x (* Yes *) * ( ń x. ń z.x) ń x. ń y.z * ( ń x. ń z.x) ń x. ń y.z (* No *) =Lambda Calculus= =Lambda Calculus (3 pts)= Give a weakly normalizing term Give a weakly normalizing term which is not strongly normalizing. which is not strongly normalizing. (* ( ń x. ń y.y) (( ń x.x x) ń x.x x) *)

  4. Example =History (5 pts)= =History= List the inventors of the List the inventors of the =History= following programming languages. following programming languages. List the inventors of the * Haskell 98 (* Hudak,PJ,Wadler *) * Haskell 98 following programming languages. * LISP 58 (* McCarthy *) * LISP 58 * LISP 58 * ML 73 (* Gordon,Milner *) * ML 73 * ML 73 =Scoping (2 pts)= =Scoping= * OCaml 87 Which of these terms are closed? Which of these terms are closed? * Haskell 90 * ń x. ń y.x * ń x. ń y.x (* Yes *) =Combinators= * ( ń x. ń z.x) ń x. ń y.z * ( ń x. ń z.x) ń x. ń y.z (* No *) Give the equations for S and K in =Lambda Calculus= =Lambda Calculus (3 pts)= a combinatory algebra. Give a weakly normalizing term Give a weakly normalizing term =Scoping= which is not strongly normalizing. which is not strongly normalizing. Which of these terms are closed? (* ( ń x. ń y.y) (( ń x.x x) ń x.x x) *) * ń x. ń y.x * ń x.( ń y.y) y * ( ń x. ń z.x) ń x. ń y.z =Lambda Calculus= Give a weakly normalizing term which is not strongly normalizing.

  5. Example =History (5 pts)= =History= List the inventors of the List the inventors of the =History (5 pts)= =History= following programming languages. following programming languages. List the inventors of the List the inventors of the * Haskell 98 (* Hudak,PJ,Wadler *) * Haskell 98 following programming languages. following programming languages. * LISP 58 (* McCarthy *) * LISP 58 * LISP 58 (* McCarthy *) * LISP 58 * ML 73 (* Gordon,Milner *) * ML 73 * ML 73 (* Gordon,Milner *) * ML 73 =Scoping (2 pts)= =Scoping= * OCaml 87 (* TODO: answer *) * OCaml 87 Which of these terms are closed? Which of these terms are closed? * Haskell 90 (* Hudak,PJ,Wadler *) * Haskell 90 * ń x. ń y.x * ń x. ń y.x (* Yes *) =Combinators (? pts)= =Combinators= * ( ń x. ń z.x) ń x. ń y.z * ( ń x. ń z.x) ń x. ń y.z (* No *) Give the equations for S and K in Give the equations for S and K in =Lambda Calculus= =Lambda Calculus (3 pts)= a combinatory algebra. a combinatory algebra. Give a weakly normalizing term Give a weakly normalizing term (* TODO: write the answer *) =Scoping= which is not strongly normalizing. which is not strongly normalizing. =Scoping (2 pts)= Which of these terms are closed? (* ( ń x. ń y.y) (( ń x.x x) ń x.x x) *) * ń x. ń y.x Which of these terms are closed? * ń x.( ń y.y) y * ń x. ń y.x (* Yes *) * ( ń x. ń z.x) ń x. ń y.z * ń x.( ń y.y) y (* TODO: answer *) =Lambda Calculus= * ( ń x. ń z.x) ń x. ń y.z (* No *) Give a weakly normalizing term =Lambda Calculus (3 pts)= which is not strongly normalizing. Give a weakly normalizing term which is not strongly normalizing. (* ( ń x. ń y.y) (( ń x.x x) ń x.x x) *)

  6. Example =History (5 pts)= =History= List the inventors of the List the inventors of the following programming languages. following programming languages. * LISP 58 (* McCarthy *) * LISP 58 * ML 73 (* Gordon,Milner *) * ML 73 * OCaml 87 (* TODO: answer *) * OCaml 87 * Haskell 90 (* Hudak,PJ,Wadler *) * Haskell 90 =Combinators (? pts)= =History (5 pts)= =Combinators= Give the equations for S and K in * Haskell 98 (* Hudak,PJ,Wadler *) Give the equations for S and K in a combinatory algebra. a combinatory algebra. * LISP 58 (* McCarthy *) (* TODO: write the answer *) =Scoping= * ML 73 (* Gordon,Milner *) =Scoping (2 pts)= Which of these terms are closed? * ń x. ń y.x Which of these terms are closed? * ń x.( ń y.y) y * ń x. ń y.x (* Yes *) * ( ń x. ń z.x) ń x. ń y.z * ń x.( ń y.y) y (* TODO: answer *) =Lambda Calculus= * ( ń x. ń z.x) ń x. ń y.z (* No *) Give a weakly normalizing term =Lambda Calculus (3 pts)= which is not strongly normalizing. Give a weakly normalizing term which is not strongly normalizing. (* ( ń x. ń y.y) (( ń x.x x) ń x.x x) *)

  7. Basic lens with complement A lens l is between a source set S and a view set V , and over a complement set C . C Notation: l ∈ S ⇐ ⇒ V

  8. Basic lens with complement A lens l is between a source set S and a view set V , and over a complement set C . C Notation: l ∈ S ⇐ ⇒ V The source S contains all the information (the full exam). =History (5 pts)= * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *)

  9. Basic lens with complement A lens l is between a source set S and a view set V , and over a complement set C . C Notation: l ∈ S ⇐ ⇒ V The view V has less information than the source (we don’t show the answers and number of points). =History= * Haskell 98 * LISP 58 * ML 73

  10. Basic lens with complement A lens l is between a source set S and a view set V , and over a complement set C . C Notation: l ∈ S ⇐ ⇒ V The complement C represents the missing information (the answers and number of points). Hudak,PJ,Wadler McCarthy 5 pts Gordon,Milner

  11. Basic lens with complement A lens comes with three functions: get, =History (5 pts)= * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *) get =History= * Haskell 98 * LISP 58 * ML 73

  12. Basic lens with complement A lens comes with three functions: get, res =History (5 pts)= * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *) res 5 pts Hudak,PJ,Wadler McCarthy Gordon,Milner

  13. Basic lens with complement A lens comes with three functions: get, res and put. =History (5 pts)= * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *) put 5 pts =History= Hudak,PJ,Wadler * Haskell 98 McCarthy * LISP 58 Gordon,Milner * ML 73

  14. Basic lens with complement l . get ∈ S → V ∈ S → C l . res l . put ∈ V → C → S These functions obey two round-tripping laws, explaining the interoperation between get, res and put. l . get ( l . put v c ) = v ( PutGet ) l . put ( l . get s ) ( l . res s ) = s ( GetPut )

  15. The alignment problem =History (5 pts)= * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *)

  16. The alignment problem =History (5 pts)= * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *) get =History= * Haskell 98 * LISP 58 * ML 73

  17. The alignment problem =History (5 pts)= * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *) get =History= =History= * LISP 58 * Haskell 98 * ML 73 * LISP 58 * OCaml 87 * ML 73 * Haskell 90 edit

  18. The alignment problem =History (5 pts)= =History (5 pts)= * LISP 58 (* Hudak,PJ,Wadler *) * Haskell 98 (* Hudak,PJ,Wadler *) * ML 73 (* McCarthy *) * LISP 58 (* McCarthy *) * OCaml 87 (* Gordon,Milner *) * ML 73 (* Gordon,Milner *) * Haskell 90 (* TODO: answer *) get put =History= =History= * LISP 58 * Haskell 98 * ML 73 * LISP 58 * OCaml 87 * ML 73 * Haskell 90 edit

  19. Challenges ◮ This problem is fundamentally heuristic ◮ “state-based” lens only sees the result of edit ◮ user intent must be inferred ◮ Appropriate heuristic depends on the application ◮ How to fit these heuristic behaviors into our principled lens framework? ◮ how to formulate clean semantic laws involving “user intent”?

  20. Matching Lenses Goals: ◮ General solution (applicable to many heuristics) ◮ Clean theory (core laws parametrized on heuristics)

  21. Structures with chunks In order to express the behavior of the put function in presence of view edits, we need to add structure to the source, view and complement types. =History (5 pts)= source * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) chunks * ML 73 (* Gordon,Milner *) whole complement view resource =History= rigid complement Hudak,PJ,Wadler * Haskell 98 5 pts * LISP 58 McCarthy * ML 73 Gordon,Milner

  22. Plan ◮ Start with something simple ◮ get does not permute the items ◮ items are not nested ◮ only one sublens is used for all items ◮ Understand it fully ◮ Relax these simplifications

  23. Simple matching lenses

  24. Mechanism =History (5 pts)= * Haskell 98 (* Hudak,PJ,Wadler *) * LISP 58 (* McCarthy *) * ML 73 (* Gordon,Milner *)

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