[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Very general OCaml questions
> 1) ---------------------- > I want to define a signpost tactic as a package of functionality with a well > defined and known signature. > Modules would be perfect, if it wasn't for the fact that I want to be able to > pass around all the signpost tactics as a list, and since modules aren't > first class data, like functions, I cannot do something like > > let tactics = [iodine; OpenVPN; Tor; etc] > > and then later call the functions defined in the modules... > > I could define the tactics as classes since I could then easily pass them > around, but I feel somewhat dirty using classes in a nice functional language. > > An option could be to combine modules and records, where the standard set of > functions are exposed in the record, and from there invoke the module > functions, but that doesn't seem very natural or clean either. > > What is the preferred approach? You can also use first-class modules: module type S = sig val f : int -> int end module A = struct let f x = x end module B = struct let f x = x * x end let modules = [| (module A : S); (module B : S) |] let f i = let module M = (val modules.(i) : S) in M.f If you are defining an abstract type in S, it becomes a bit more complex, but otherwise it's fine. -- Thomas
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |