Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Expression Problem solved, finally!

How object algebras, or "fold-algebras" can be used to represent data and how its encoding as typeclasses or interfaces help with the Expression Problem.

  • Login to see the comments

The Expression Problem solved, finally!

  1. 1. The Expression Problem solved, Finally! FPSyd
  2. 2. Disclaimer
  3. 3. I had this problem before Result Failure Success Pending Console Html Screenshot? Pdf?
  4. 4. The Expression Problem Add(Lit(1), Lit(2))
  5. 5. The Expression Problem
  6. 6. The Expression Problem
  7. 7. Solved in Java?!?
  8. 8. Not a new problem
  9. 9. Once and for all
  10. 10. Once and for all
  11. 11. Once and for all
  12. 12. Type constructors?
  13. 13. Type constructors?
  14. 14. Data types encodings
  15. 15. Data types encodings F[A] -> A (T1 + T2 + … + Tn) -> A (T1 -> A, T2 -> A, …, Tn -> A)
  16. 16. Data types encodings
  17. 17. Extensibility
  18. 18. Extensibility
  19. 19. Extensibility
  20. 20. Extensibility Data Functions Dispatchers
  21. 21. Main points Data types as Folds (!= F-Algebras) Encoded as type-classes Extensible and modular
  22. 22. “Finally tagless”
  23. 23. Finally tagless Embedded DSLs “Initial” “Final”
  24. 24. Extensibility “Initial”
  25. 25. Extensibility “Final”
  26. 26. Some other problems • The tagging problem in the interpretation of typed higher-order languages • The pattern-matching problem • Many others… “The [deserialization] problem becomes much more frustrating, exhilarating, time consuming and addictive in the general case of higher-order typed embedded languages” - Oleg Kiselyov
  27. 27. The tagging problem
  28. 28. One approach
  29. 29. With GADTs
  30. 30. The “Symantics” approach
  31. 31. Pushing the negation down “Initial” neg (add 1 2) => add (neg 1) (neg 2)
  32. 32. Pushing the negation down “Final”
  33. 33. Bijection between “ I n i t i a l ” and “Final”
  34. 34. Advantages Expressions are well-typed Easily extensible Less demanding of the type system
  35. 35. With OO
  36. 36. The Visitor solution
  37. 37. Object algebra
  38. 38. Pretty printer
  39. 39. Pretty printer
  40. 40. Extensions
  41. 41. Extensions
  42. 42. Multi-type
  43. 43. Combining data
  44. 44. Combining operations
  45. 45. Object algebras Fold algebras Work with OO languages having generics No visitor and “accept” method Generic combinator classes?
  46. 46. Conclusion Fold algebras Easier on the type system Extensibility Shallow / Deep Embeddings – ICFP14

×