Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang polymorphism: multiple implementations of the same contract?

What's correct Erlang way to have separated implementations from the contract and how to switch between them?

like image 477
user3169252 Avatar asked Mar 10 '14 22:03

user3169252


1 Answers

While others mention the behaviour feature, it is merely a small helper to make sure you implement all functions in a module for a callback structure. If you have two implementations, a and b, and both implements the same functions, you can just statically substitute a for b in a calling module. For static configuration where you have a better implementation, this is preferable.

If the question is of a more dynamic nature, you can just do

 Mod = a,
 Mod:f(Args).

And then in code set Mod appropriately. This lets you dynamically control what module to call while the program is running. It is not entirely clear which of the two you want.

like image 129
I GIVE CRAP ANSWERS Avatar answered Sep 30 '22 17:09

I GIVE CRAP ANSWERS