Parametrically customized subtypes

I think this is the same feature discussed recently by the Symbolics and Julia compiler teams. I would be interested to see what the experts have to say on this topic.

For each of many external abstract types T , I want to make a new abstract subtype of T whose dispatch users control.

For example, a const LazyInteger = Lazy{Integer} that’s a subtype of Integer but has custom lazy method implementations.

I can implement this for certain types manually, but I don’t think it’s currently possible to represent the idea of customized subtypes of types like

abstract type Lazy{T} <: T end

What applications does this feature enable? What are the problems with it? What are the alternatives?


@Keno, @ChrisRackauckas, and others might have thoughts on this?

This couldn’t work in this form because if T is concrete it would violate a fundamental design principle of Julia, that all concrete types are final.

You’d need to be able to make a subtype of some supertype of T, but it’s not clear how you would designate which supertype to use.

3 Likes

(deleted)

We’ve been discussing this a fair bit from the Symbolics perspective. Adding things like this to the language wholesale is too invasive. We’re looking into instead making things like GitHub - MasonProtter/SymbolicTracing.jl: (experimental) tracing and abstract interpretation with SymbolicUtils.jl easier.

2 Likes

Indeed, as mentioned in a big Zulip thread, I just talked with Jeff and Keno today and our plan is to use SymbolicTracing as the approach, and try and find ways to make the macro act nicely on full functions, modules, and within the REPL so that you can get this behavior without invading the compiler.