Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] mutually dependent modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Issac Trotts <ijtrotts@u...>
Subject: Re: [Caml-list] mutually dependent modules
Chris Hecker wrote:

>
>> Let's suppose that we have two mutually dependent modules, a.ml and
>> b.ml, i.e. in b.ml there is a call like A.f1() and in a.ml there is a
>> call like B.f2(). The question is how to link these modules?
>
>
> You can't.  Caml doesn't support circular references in modules.  
> Search the list for lots of threads and in-depth discussion on this topic.
>
> Chris

It's easy to get the desired effect.


let print = print_endline

module A = struct
  let rec f1() = (!f2)(); print "A.f1"
  and f2 = ref(fun () -> ())
end;;

module B =
struct
  let f1 = ref(fun () -> ())
  let f2 () = print "B.f2"
  let f3 () = (!f1)()
end;;

let _ = A.f2 := B.f2
let _ = B.f1 := A.f1
let _ = A.f1()
let _ = print "--"
let _ = B.f3();;

Issac



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners