## Any recent developments on "active libraries" that I'm missing?

I'm interested in libraries that guide compilers for optimizations, but it
seems like there isn't much literature on this topic.

- Papers like "Generative Programming and Active Libraries" which usually just
briefly talk about the idea and give the same examples like Blitz++.

- There's a thesis, "Active Libraries and Universal Languages", which as far as
I can see is a bit too light on the practical examples and implementation.

Two implementations that work well:

- I think Haskell libraries that use GHC's rewrite rules are "active libraries"
in this sense

- The stream fusion library described in POPL'17 paper "Stream Fusion, to
Completeness" is an example that's a recent work and one that works really
well (although it has problems like leaking code type to the user in
functional arguments).

These are pretty much all I can think of as examples. I'm looking for recent
developments and other practical examples (i.e. ones that work well and/or used
widely). Any pointers would be appreciated.

## Comment viewing options

### Old features

Haskell, C++, and Felix at least can do this in a very powerful way, although its hardly what you'd call a recent development:

At least for type classes in principle, providing a more specialised instance of a function is clearly an optimisation and a hard instruction to the compiler to select it by preference. C++ also has class specialisations as well as method specialisations, which are roughly equivalent to type class instance specialisations.

I guess this wasn't what you were looking for but it does fit your specification :)

FYI Felix also has user defined reductions like:

reduce revrev[T] (x:list[T[]) : x.rev.rev => x;


which are similar to the same facility in Haskell. Unfortunately such features are very expensive to use and do not work very well: they seem to only trigger by luck due to interaction with other optimisations which hide the specific "shape" required. In fact in Felix these used to be applied during the optimisation phase, and monomorphisation was done during code generation, but since a separate monomorphisation phase is now used prior to optimisation polymorphic reductions that apply to nominal types or named functions no longer work.

I have some hope to introduce something like

reduce strcat (x:string, y:string) : x + y => revcat (list(y,x));
reduce strcat (x:list[string], y:string): revcat x + y => revcat (Cons (y,x));


as a way to dramatically improve string concatenation performance, which has some chance of working, being monomorphic, but frankly some cheating the compiler with special handling for this is easier to implement than a generic reduction feature.

### Several of my recent

Several of my recent research papers can be classified as relating to active libraries. In particular:

Programmable Semantic Fragments: The Design and Implementation of typy (GPCE 2016)
(libraries can extend the type system)

Safely Composable Type-Specific Languages (ECOOP 2014)
(libraries can define new syntactic sugar)

Active Code Completion (ICSE 2012)
(libraries can define new edit-time code generation interfaces)

The relevant links are available from my website:

http://www.cs.cmu.edu/~comar