Loading ...
Sorry, an error occurred while loading the content.

9074Re: Circular dependencies between modules

Expand Messages
  • Remi Vanicat
    Dec 1, 2007
    • 0 Attachment
      Fabrice Marchant <fabrice.marchant@...> writes:

      > If two.ml uses several one.ml components, so they appear in this order :
      > one.ml two.ml in the Makefile, a cheat to access a two.ml component
      > inside one.ml would be :
      > to define a reference to None inside one.ml,
      > to reinitalize this reference, at runtime from two.ml, with Some copy of
      > this wanted two.ml component.
      > 'option' use causes the things to be heavier but otherwise they would
      > become not only ugly but even unsafe.
      > But maybe I'm wrong and there is a better way...

      If the reference is a function, you can also use this :

      in one.ml:
      let f : (int -> string -> string) ref =
      ref(fun _ _ _ -> failwith "not implemented yet")

      in two.ml

      let f x y z = "do the real stuff"

      One.f := f

      There is several problem with this:
      - you need to explicitly give the type of f in one.ml,
      - this type must not be polymorphic.
      - this will only work with function.

      --
      RĂ©mi Vanicat
    • Show all 15 messages in this topic