Extending a Package (without forking)

I have a package that I wrote which is part of the Julia package registry that I would like to extend in a nonstandard way. It’s organized in the same spirit as Optim.jl in the sense that there are a much of different solver methods that the user can invoke, and it makes use of multiple dispatch to use them smoothly.

For a particular problem I’m working on, I need a custom solver which is not part of the existing package, and it is far too specialized to merit including in it. I was hoping to be able to do something like:

using MyPackage

and then be able to use all of the interfaces associated with MyPackage but with my custom solver. However, this generates a type error, presumably because MyPackage wasn’t built with the custom_method1.jl file as part of its source.

Other than just forking the package, is there a way to get Julia to support such an extension?

It’s hard to say without more specifics but there shouldn’t be an issue with extending a registered package. Ideally the original package defines an abstract type and the appropriate functions for it, so when you extend it for your use case it’s not an issue. If it doesn’t do it, one possible workaround would be to have a convert function that transforms your type into the types in the original package so you can reuse the methods there.