Is there a commonly-understood name for this pattern?

There’s a common pattern in Elixir libraries where an “implementation module” is used by generic functions provided by the library, and the library provides a use macro that takes care of filling in the correct parameter automatically.


  • Ecto.Repo uses this technique to pass the name of the module it’s used in to functions in Ecto.Repo.Schema:
  • Guardian uses this technique both for it’s core functions as well as for a plug; it’s where I got the term “implementation module” from:

Is there a name for this pattern? “Specialization”? “Compile-time currying”?

1 Like

I’m not sure there is a name for it, but instance module might be quite fitting. Basically the module holding the use call becomes the API into a specific instance of the service provided by the library. It’s a convenience over needing the user supply common config per instance over and over again. The use macro itself is basically a instance or wrapper factory.