topics related to the expression problem
play

Topics related to the Expression Problem including but not limited - PowerPoint PPT Presentation

Topics related to the Expression Problem including but not limited to Compositional and Linear Encoding (of Synthesized and Inherited Attributes as Object Algebras in Scala) Tillmann Rendel University of Tbingen, Germany Invited Talk by


  1. trait Alg[ T ] { Final Embedding def Lit( n : Int): T def Add( l : T , r : T ): T } trait Exp { def fold[T](alg: Alg[T]): T } def Lit( n : Int) = new Exp { def fold[ T ]( alg : Alg[ T ]) = alg .lit( n ) } def Add( l : Exp, r : Exp) = new Exp { def fold[ T ]( alg : Alg[ T ]) = alg .Add( l .fold( alg ), r .fold( alg )) } 11/42

  2. To study the relationship of embedding approaches, we should study defunctionalization and refunctionalization 12/42

  3. To study the relationship of embedding approaches, we should study defunctionalization and refunctionalization (for Scala-ish languages?!) 12/42

  4. Modular, Scalable, and Compositional Encoding (of Attribute Grammars in Scala) Rendel, Brachthäuser, Ostermann 2014 (From Object Algebras to ...) 13/42

  5. Two Dimensions of Modularity constructors consumer 14/42

  6. Third Dimension of Modularity To scale to large programs, solutions to the expression problem need to support components with inner structure: ● Consumers that depend on other consumers. ● Consumers that depend on context information. ● Consumers that are fused together. 15/42

  7. Bottom-Up Data Flow 16/42

  8. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  9. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  10. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  11. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  12. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  13. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  14. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  15. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  16. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  17. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ def Lit: Int n def Add: ( E , E ) ⇒ def Add = ( e 2 , e 3 ) ⇒ E e 2 + e 3 } } 17/42

  18. Top-Down Data Flow 18/42

  19. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ def Add 1 : E true def Add 2 : ( E , E ) ⇒ def Add 2 = ( e 1 , e 2 ) ⇒ E false } } 19/42

  20. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ def Add 1 : E true def Add 2 : ( E , E ) ⇒ def Add 2 = ( e 1 , e 2 ) ⇒ E false } } 19/42

  21. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ def Add 1 : E true def Add 2 : ( E , E ) ⇒ def Add 2 = ( e 1 , e 2 ) ⇒ E false } } 19/42

  22. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ def Add 1 : E true def Add 2 : ( E , E ) ⇒ def Add 2 = ( e 1 , e 2 ) ⇒ E false } } 19/42

  23. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ def Add 1 : E true def Add 2 : ( E , E ) ⇒ def Add 2 = ( e 1 , e 2 ) ⇒ E false } } 19/42

  24. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ def Add 1 : E true def Add 2 : ( E , E ) ⇒ def Add 2 = ( e 1 , e 2 ) ⇒ E false } } 19/42

  25. Composition 20/42

  26. Composition compose 20/42

  27. Composition compose 20/42

  28. Composition assemble 20/42

  29. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  30. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  31. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  32. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  33. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  34. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  35. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  36. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  37. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[Mix[A, B]] = { ... 21/42

  38. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]( implicit m: Mix[A, B]): ( A , B ) ⇒ A with B Implicit Macros implicit def mixAll[A, B]: Mix[A, B] = macro impl[A, B] def impl[A, B](c: Context)(implicit aT: c.WeakTypeTag[A], bT: c.WeakTypeTag[B]): c.Expr[ Mix [A, B]] = { ... 21/42

  39. compose( , ) = Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ def Lit: Int O def Add: ( E , E ) ⇒ C ⇒ O } 22/42

  40. compose( , ) = Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ def Lit: Int O def Add: ( E , E ) ⇒ C ⇒ O } 22/42

  41. compose( , ) = Dependency Tracking trait Sig[- E , - C , + O ] { current node ⇒ C ⇒ def Lit: Int O def Add: ( E , E ) ⇒ C ⇒ O } 22/42

  42. compose( , ) = Dependency Tracking trait Sig[- E , - C , + O ] { current node ⇒ C ⇒ def Lit: Int O def Add: ( E , E ) ⇒ C ⇒ O } children 22/42

  43. compose( , ) = Dependency Tracking context from parent trait Sig[- E , - C , + O ] { current node ⇒ C ⇒ def Lit: Int O def Add: ( E , E ) ⇒ C ⇒ O } 22/42

  44. compose( , ) = Dependency Tracking trait Sig[- E , - C , + O ] { current node ⇒ C ⇒ def Lit: Int O def Add: ( E , E ) ⇒ C ⇒ O } 22/42

  45. compose( , ) = Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ def Lit: Int O def Add: ( E , E ) ⇒ C ⇒ O } 22/42

  46. compose( , ) = Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ def Lit: Int O def Add: ( E , E ) ⇒ C ⇒ O } 22/42

  47. compose( , ) = Composing two algebras def compose [E 1 , C 1 , O 1 , E 2 , C 2 >: C 1 with O 1 , O 2 ] (alg 1 : Sig[E 1 , C 1 , O 1 ], alg 2 : Sig[E 2 , C 2 , O 2 ]): Sig[E 1 with E 2 , C 1 , O 1 with O 2 ] 23/42

  48. compose( , ) = Composing two algebras def compose [E 1 , C 1 , O 1 , E 2 , C 2 >: C 1 with O 1 , O 2 ] (alg 1 : Sig[E 1 , C 1 , O 1 ], alg 2 : Sig[E 2 , C 2 , O 2 ]): Sig[E 1 with E 2 , C 1 , O 1 with O 2 ] 23/42

  49. compose( , ) = Composing two algebras def compose [E 1 , C 1 , O 1 , E 2 , C 2 >: C 1 with O 1 , O 2 ] (alg 1 : Sig[E 1 , C 1 , O 1 ], alg 2 : Sig[E 2 , C 2 , O 2 ]): Sig[E 1 with E 2 , C 1 , O 1 with O 2 ] 23/42

  50. compose( , ) = Composing two algebras def compose [E 1 , C 1 , O 1 , E 2 , C 2 >: C 1 with O 1 , O 2 ] (alg 1 : Sig[E 1 , C 1 , O 1 ], alg 2 : Sig[E 2 , C 2 , O 2 ]): Sig[E 1 with E 2 , C 1 , O 1 with O 2 ] 23/42

  51. compose( , ) = Composing two algebras def compose [E 1 , C 1 , O 1 , E 2 , C 2 >: C 1 with O 1 , O 2 ] (alg 1 : Sig[E 1 , C 1 , O 1 ], alg 2 : Sig[E 2 , C 2 , O 2 ]): Sig[E 1 with E 2 , C 1 , O 1 with O 2 ] 23/42

  52. compose( , ) = Composing two algebras def compose [E 1 , C 1 , O 1 , E 2 , C 2 >: C 1 with O 1 , O 2 ] (alg 1 : Sig[E 1 , C 1 , O 1 ], alg 2 : Sig[E 2 , C 2 , O 2 ]): Sig[E 1 with E 2 , C 1 , O 1 with O 2 ] 23/42

Recommend


More recommend