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

9073Re: Circular dependencies between modules

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

      > Thanks Jon !
      >
      >> > There are workarounds ( I've even written an ugly one in order not to let
      >> > my build stuck ) but I hope to learn what would be a clean way to perform
      >> > this.
      >>
      >> Yes, you need to break the cyclic dependence by parameterizing one definition
      >> over another.
      > Please Jon, could you develop a bit more on this ?
      > I'm unable to see what you mean here.

      Well, as I forget this possibility in my late post, I will show you
      here:

      For type:

      you have in one.ml:

      type t1 =
      Foo of Two.t2
      | Bar of int

      in two.ml

      type t2 =
      Fooz of One.t1 * int

      of course this wont work, but you can do :

      you have in one.ml:

      type 'a t1 =
      Foo of 'a
      | Bar of int

      in two.ml

      type t2 =
      Fooz of One.t1 * int | Leaf


      then one can use Foo(Fooz(Bar 10)) : we use parametrization of the
      first type to break the cycle.

      In the same way, you could add an argument to a function so instead to
      depend on value at compile time, it will only need it when evaluated.




      >
      >> Having big cyclic dependencies is a bad idea anyway...
      > Ah ! I wondered whether the need of such cyclic dependency didn't
      > reveal some misconception.

      It might. Note that I learn the ref trick wile reading Ocaml source:
      cyclic dependency can come from misconception, but sometime, it is the
      way to go.


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