Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] double-functors for types and values
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Naylor <bwv211mail@y...>
Subject: [Caml-list] double-functors for types and values
It frequently happens that I have a module/functor A parameterized by
module B, but B depends on types that are part of A.  Those types of A in
turn depend on the types of B.  Wow, I've confused myself already.  Let me
try to make this clearer:

    let A.avalue = ... B.bvalue ...
    val B.bvalue : ... A.atype ...
    type A.atype = ... B.btype ...

This results in the following kind of double-functor, one functor for the
types and the second internal functor for the values:

module A = struct

  module Types (B_types : sig type btype end) = struct

    type atype = ... B_types.btype ...

    module Values (B_values : sig val bvalue : ... atype ... end) = struct

      let avalue = ... B_values.bvalue ...


module B = struct

  type btype = ...

  module A_types = A.Types (struct type btype = B.btype end)

  let bvalue = ...

  module A_values = A_types.Values (struct let bvalue = B.bvalue end)

  let _ = ... A_values.avalue ...


So, my questions are:

(1) is this a normal way of structuring this kind of thing?  I know I could
    use polymorphic types instead of trying to make it work in the module
    system, but I like the idea that all my types are made explicit.

(2) do I pay a run-time cost for functor applications that only contain
    types?  In other words, does A_values.avalue suffer a double
    indirection since it is buried two functors deep?  Or do you only pay
    the indirection cost for values that are passed across functorial

Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: