[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Very general OCaml questions



> 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

Ah, this feels like what I was intuitively looking for.
Thanks Thomas!

All the best,
Sebastian


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.