caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* mutually recursive modules
@ 2008-03-22 19:22 Jacques Le Normand
  2008-03-22 19:37 ` [Caml-list] " Daniel Bünzli
  0 siblings, 1 reply; 10+ messages in thread
From: Jacques Le Normand @ 2008-03-22 19:22 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 95 bytes --]

Hello caml-list
is it possible to put mutually recursive modules in different files?
--Jacques

[-- Attachment #2: Type: text/html, Size: 105 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread
* mutually recursive modules
@ 2006-01-17  8:55 Brendan Miller
  2006-01-17 10:21 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 10+ messages in thread
From: Brendan Miller @ 2006-01-17  8:55 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 10+ messages in thread
* [Caml-list] mutually recursive modules
@ 2005-12-02 10:15 Jonathan Roewen
  2005-12-06 17:33 ` Alain Frisch
  0 siblings, 1 reply; 10+ messages in thread
From: Jonathan Roewen @ 2005-12-02 10:15 UTC (permalink / raw)
  To: caml-list

Hi,

Can one make mutually recursive modules (inside the one .ml file of course)?

Jonathan


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-03-24  9:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-22 19:22 mutually recursive modules Jacques Le Normand
2008-03-22 19:37 ` [Caml-list] " Daniel Bünzli
2008-03-22 21:20   ` ketti
2008-03-23 16:59     ` Jacques Le Normand
2008-03-23 18:37       ` ketti
2008-03-24  9:21         ` rossberg
  -- strict thread matches above, loose matches on Subject: below --
2006-01-17  8:55 Brendan Miller
2006-01-17 10:21 ` [Caml-list] " Jacques Garrigue
2006-01-17 12:13   ` skaller
2005-12-02 10:15 Jonathan Roewen
2005-12-06 17:33 ` Alain Frisch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).