Consider the following design problem. I have a set of function f1...fn
f1 : 'a -> string f2 : 'b -> string ... fn : 'z -> string These functions are mutually recursive, meaning that they can call each other. The computation starts with the call of one of the functions (depending at runtime), continues calling the others (in an order decided at runtime), and ends with the returned string. So the result of their computation is always a string. Sometimes i want to apply edit : string -> string to a substring of the result, before it is returned. The problem is that - the decision about whether or not apply "edit" is taken by the caller of the f1..fn but - the decision about which substring edit must be applied to, is taken by one (or two) of these functions I found two solutions but i am not satisfied by any of them. 1) The first solution is passing edit to the functions. Types are changed accordingly: f1 : (string -> string ) -> 'a -> string f2 : (string -> string ) -> 'b -> string ... fn : (string -> string ) -> 'z -> string If I want to apply edit, I pass it to the function i want to call. Otherwise I pass the Identity function. The disadvantage is the code gets less maintainable since, in this case, i must pass every time the edit function (even in the calls between f1...fn). If f1..fn were not mutually recursive i could add one more parameter _only_ to the f that must apply edit. 2)The second possibility is to make a parametric module using a functor, like module FunctionSet = functors (edit_module : EditModule) -> struct f1 : 'a -> string f2 : 'b -> string ... fn : 'z -> string end;; where EditModule contains edit. module type EditModule = sig edit : string -> string end;; This solution is elegant but has a big limit: the edit function must be completely defined at compile time, since I can not define an EditModule at runtime (i suppose). Since the edit i want to apply changes at runtime, this approach is not an option :( How would solve this problem? -- You received this message because you are subscribed to the Google Groups "ocaml-developer" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/ocaml-developer?hl=en For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html
