caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brendan Miller <catphive.lists@gmail.com>
To: caml-list@inria.fr
Subject: mutually recursive modules
Date: Tue, 17 Jan 2006 00:55:30 -0800	[thread overview]
Message-ID: <3dd983220601170055w5bd95adfjca47847809f3226e@mail.gmail.com> (raw)

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


             reply	other threads:[~2006-01-17  8:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-17  8:55 Brendan Miller [this message]
2006-01-17 10:21 ` [Caml-list] " Jacques Garrigue
2006-01-17 12:13   ` skaller
2008-03-22 19:22 Jacques Le Normand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3dd983220601170055w5bd95adfjca47847809f3226e@mail.gmail.com \
    --to=catphive.lists@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).