[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Brendan Miller <catphive.lists@g...> |
| Subject: | mutually recursive modules |
I'm new to ocaml. My understanding is that the ocaml compiler does not allow for circular dependancy of modules. What is the design reason for this? I don't think I've ever seen a language before with this limitation. Is it just to keep people from writing mutually recursive functions across modules? Suppose there are two classes, A and B defined in separate modules. Does the no circular dependancy rule preclude a doubly linked relationship between A and B? Let's say I want to create a doubly linked list with alternating element types. consider the following code, which fails to compile: A.mli: class c : object method set_prev : B.c -> unit method get_prev : B.c method set_next : B.c -> unit method get_next : B.c end A.ml class c = object val mutable m_prev : B.c option = None val mutable m_next : B.c option = None method set_prev prev = m_prev <- prev method get_prev = m_prev method set_next next = m_next <- next method get_next = m_next end;; B.mli class c : object method set_prev : A.c -> unit method get_prev : A.c method set_next : A.c -> unit method get_next : A.c end B.ml class c = object val mutable m_prev : A.c option = None val mutable m_next : A.c option = None method set_prev prev = m_prev <- prev method get_prev = m_prev method set_next next = m_next <- next method get_next = m_next end;; This is annoying. Of course I need a way to make classes from different modules recur. Is there a syntax for specifying an interface to the type I'm recurring with without that type actually being in the same module? That would be somewhat cumbersome, but would actually more properly separate the types than the code above. In general, could someone clarify the rational for making type recursion so cumbersome? thx