I want to write a function that can take a list (or some other structure) of functions as an argument, and another argument whose type will be used to determine which function to use from the list.
For example, let add1 = (fun (x : int) → x + 1), and let f1 = (fun (x : string) → x), and I want to write a function func : some_function_list → arg2_type → output_type, where if its second argument is a string, it gives the argument itself, and if the second argument is an integer, it returns the argument plus 1.
The reason I say a list of function is that the list can be changed dynamically, so if the function func meets an arg2 that matches certain criteria, it might recursively call it self with a different first argument (i.e. func (some_new_function :: some_function_list) arg2).
Is it possible to do this with any of the advanced features of OCaml, or do I have to use some more dynamic language?