Optional multiple dispatch with Glue Packages?

mkitti
Wed, 25 Jan 2023 01:04:00 +0000
Internals & Design

Now that built in glue packages are on their way, I wonder if it is worthwhile to consider a new design pattern of optional multiple dispatch.

Typically in Julia we tend to take advantage of multiple dispatch rather than having multiple distinct functions with similar names in each package. For example, there is one Base.length(), and we tend to use multiple dispatch to overload this method for new types we introduce. Doing so however can lead to frustrating compilation issues such as method invalidation.

Alternatively, we could create FooPackage.length() and BarPackage.length(), but this would lead us to use namespace separation as is common in Python.

With glue packages, I see the potential for a middle ground between these two approaches.

The core package does no overloading of external methods and only provides types and methods confined to its module namespace. At the extreme, these types also do not inherit from any abstract types from outside the package.

Rather the task of overloading methods and extending types falls to an integration glue package. This glue package merely overloads methods from other packages or Base and then forwards the functions calls to their actual implementation within the core package namespace via inlining.

Some packages have already proceeded down this road and created “*Core” packages. In some cases, core packages consist mainly of type and their constructors and not much else. While this approach certainly is effective at preventing invalidations, it also means the “Core” package is practically useless on its own.

What I am asking for here is a clearer understanding of what a core package is. Can we design a core package that avoids the compilation issues associated with multiple dispatch but is still functional? Can we design a glue package that merely acts as a way to opt into the multiple dispatch paradigm?

9 posts - 4 participants