Like C/C++'s header file, I’m wondering if it’s possible for Julia to introduce similar concepts so that package authors can have a smaller dependencies and thus reduce the latency.
In valid Julia semantics, this can be done via separating the package into two packages: 1) an “lightest” package with pure definitions, and 2) the implementations. For instance:
# FooInterface.jl
module FooInterface
struct MyType end
function f end
end
# Foo.jl
module Foo
using FooInterface: f, MyType
f(::MyType) = ...
map(::typeof(f), x::MyType) = ...
end
For package Bar.jl that depends on Foo.jl, the author can choose to instead depends on FooInterface.jl if Bar.jl uses Foo.jl only for dispatching purposes. Because to implement the functionality of f
, Foo usually introduces extra dependencies, and these dependencies are not necessary to make Bar.jl work.
By doing this, the package Bar now depends on a lighter dependencies, thus 1) using Bar
can be faster, and 2) maintaining Bar.jl’s compatibility is easier. Will this improve the overall TTFP status? I’m not sure.
The disadvantage is that if the package author wants to follow this strategy, he has to maintain double packages, double CI settings, and to open double PRs, trigger registrator twice… I believe this is why this strategy is not adopted massively in Julia.
I open this discussion to ask if it’s possible for Julia to support this “separating out interface package” strategy at language level so that package author can benefit from the lighter dependency without the extra maintenance burden.
Just for inspiration, the syntax can be something like this:
module Foo
@interface
struct MyType end
@interface
function f end
module Bar
@interface using Foo: MyType
g(::MyType) = ...
h(::typeof(f)) = ...
end