Dispatching on module to prove ownership in package extensions

In Julia 1.10+ you can have a module as a type parameter and do something like (using the same example as in the talk):

julia> module HYPRE end;

julia> module Pardiso end;

julia> struct Algorithm{T} end

julia> f(::Algorithm{HYPRE}) = "HYPRE"
f (generic function with 1 method)

julia> f(::Algorithm{Pardiso}) = "Pardiso"
f (generic function with 2 methods)

julia> f(Algorithm{HYPRE}())
"HYPRE"

julia> f(Algorithm{Pardiso}())
"Pardiso"

That might be one way to use dispatch for it.

3 Likes