Type piracy is when you define a method for a function you do not own with a signature where none of types are owned by you. E.g. Base.show(::IO, ::Int). It’s a matter of discussion whether a parameter owned by you counts, e.g. is Base.show(::IO, ::Vector{MyType}) type piracy?
Although in your example your MyType only occurs as a parameter, it’s in the very special type Type, so few people would claim that’s type piracy.
I’m almost certain owning T doesn’t mean you own OtherModule.NotMyType{T}. Even the Julia docs discourage the practice: Style Guide · The Julia Language. Type is typically only an exception when implementing interface methods that require adding Type methods, such as eltype or IndexStyle.
Base specifically implements Base.show(::IO, @nospecialize(::Type)). Even if we consider implementing show(::IO, ::Type{MyType}) to not be type piracy, I believe it is inadvisable since it would invalidate anything that attempts to print a type.
It probably should have a different word from “piracy”, but the devs have been quite clear over the years that they do not want you to claim ownership of a dispatch signature just because you own one of the parameters, especially in the case of Type.
The only exception is functions that basically tell you that you should be overloading them based on a parameter because it’s a part of their interface (e.g. convert).
@jakobnissen That was a really good summary. Mechanically, I knew all of that, but I didn’t appreciate the implications. Thank you.
I assumed that Moshi.jl relied on union splitting in my original post, but it actually doesn’t. It explicitly introduces if branches, so it should work regardless of compiler heuristic:
julia> @macroexpand1(@match x begin
x::Int=> 4
end)|> MacroTools.striplines
quote
var"##value#285" = x
begin
if var"##value#285" isa Int && begin
var"####TypeAnnotate#288#x#1" = var"##value#285"
true
end
var"##return#287" = let x = var"####TypeAnnotate#288#x#1"
4
end
@goto var"##final#286"
end
end
(Base).error("matching non-exhaustive")
(Base).@label var"##final#286"
var"##return#287"
end
Answering my own question: Moshi.jl’s @match is unrelated to the ADT part, and could be turned into a separate package.
This leads me to wonder what is the difference between Moshi’s @match and MLStyle’s…