Hello, I'm developing some algorithms in OCaml which need some parts to be "pluggable" so that part of the computation is left to specific computators.
Just to make an example suppose I have a signature like this one:
module type Algorithm = sig
val feed : float -> unit
val nth : int -> (float -> float)
end
And two different implementations that will be Alg1
and Alg2
. This Algorithm
module should represent the interface for various implementations like these two one.
Now I need another component, let's call it Executor
that will be the module that uses Alg1
or Alg2
throught their interface..
Reading about functors it seems that I should need a functor that takes an Algorithm
and produces a ConcreteExecutor
with a specific implementation of the algorithm I need. So that Executor
is a sort of module that is parametrized over one of its components..
Am I right? Is it the best way to obtain what I need? I'm wondering thinkgs like these because I come from a Java/C++ background so I'm used to use interfaces and abstract classes and I need to get into this functor/module abstraction issue in the correct way.
Which is the correct syntax to obtain what I want?
Thanks in advance