

Modular, composable, typed optimizations in the tagless-final style - edwintorok
http://okmij.org/ftp/tagless-final/course/optimizations.html

======
skybrian
I only understood the first part, but representing an AST as an interpreter is
interesting. Does this require a functional-style language or could a similar
thing be done in, say, Java?

~~~
barkmadley
You probably could, but there would be lots of extra boiler plate that
distract from the central idea.

The OCaml language features that are used that would need to be emulated
somehow in Java:

* Sum types (type a = A of int | B of float). Think tagged unions [1].

* Module functors (module NAME(PARAM : MODULE_TYPE) = struct ... end). Think package level functions (you get some of this with dependency injection frameworks, but it's probably no-where near as safe/sane and flexible.

* GADTs (type a = A : int -> int | int term). I'm not sure how you would represent these in java, I'm not fully up to speed on how they work yet.

[1]:
[http://en.wikipedia.org/wiki/Tagged_union](http://en.wikipedia.org/wiki/Tagged_union)

