"Adjusting" calling context of a function

Best explained by an example. Lets say I want to call:

Calendar.ISO.naive_datetime_to_string(year, month, day, hour, minute, second, microsecond)

From another calendar module that implements @behaviour Calendar. Calendar.ISO.naive_datetime_to_string calls time_to_string(hour, minute, second, microsecond) under the covers, resolved to be in the Calendar.ISO module.

But … it also calls date_to_string(year, month, day) which I’d like to be called as the version in my Calendar module.

I don’t think this is possible (and quite possible its even “bad”) but I’ve found a few situations where I’d like to delegate a function call to another module, but have the inner functions be resolved to my module. Behaviour-based modules is quite a good example of where this can crop up I think,

What’s wrong with :

@impl true
def naive_datetime_to_string(year, month, day, hour, minute, second, microsecond) do
  date_to_string(year, month, day) <> " " <> Calendar.ISO.time_to_string(hour, minute, second, microsecond)
end

and use that instead of Calendar.ISO.naive_datetime_to_string? i.e. provide the alternate implementation where desired and only use the original implementation where needed.

In a way you seem to be looking for dynamic dispatch of a polymorphic operation typically implemented in class-based languages.