I am in the process polishing up a package API before registering. The API works with “models” (arbitrary structures, the user defines them), and requires that certain transformations are available for each model (eg “simulate this model with the given parameters”).
The current API requires that
- the user defines a type (eg
struct) for a new model type,
- implements 4 methods that dispatch on this type.
Eg minimal (stylized, non-working) example of how one would this style:
using ThePackage import ThePackage: simulate struct MyModel ... end simulate(m::MyModel, params) = ...
This works fine. But am slightly uneasy about an API that requires that the user defines methods for functions.
Instead, I could ask for the model type and a bunch of closures that define these transformations. But I expect that the user would define the methods (possibly under some arbitrary function) anyway, as they are easier to program that way.
This is a style question, suggestions and existing examples of packages that do something similar would be appreciated. It may turn out that the style is totally idiomatic and I am worrying about nothing, and requiring the users to define types and methods for some API is idiomatic.