This is called the expression problem.
http://homepages.inf.ed.ac.uk/wadler/papers/expression/expre...
http://stackoverflow.com/a/2079678 is a great SO answer on this topic.
http://homepages.inf.ed.ac.uk/wadler/papers/expression/expre...
http://stackoverflow.com/a/2079678 is a great SO answer on this topic.
Video: https://www.infoq.com/presentations/object-algebras
Paper: https://www.cs.utexas.edu/~wcook/Drafts/2012/ecoop2012.pdf
I understand that there is a comparable solution in FP languages called finally tagless interpreters: https://oleksandrmanzyuk.wordpress.com/2014/06/18/from-objec...