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; 7+ 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] 7+ messages in thread

* Re: [Caml-list] mutually recursive modules
  2008-03-22 19:22 mutually recursive modules Jacques Le Normand
@ 2008-03-22 19:37 ` Daniel Bünzli
  2008-03-22 21:20   ` ketti
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Bünzli @ 2008-03-22 19:37 UTC (permalink / raw)
  To: caml-list caml-list


Le 22 mars 08 à 20:22, Jacques Le Normand a écrit :

> is it possible to put mutually recursive modules in different files?

No.

Daniel


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

* Re: [Caml-list] mutually recursive modules
  2008-03-22 19:37 ` [Caml-list] " Daniel Bünzli
@ 2008-03-22 21:20   ` ketti
  2008-03-23 16:59     ` Jacques Le Normand
  0 siblings, 1 reply; 7+ messages in thread
From: ketti @ 2008-03-22 21:20 UTC (permalink / raw)
  To: Daniel Bünzli; +Cc: caml-list caml-list

>  > is it possible to put mutually recursive modules in different files?
>
>  No.

Yes.
If you wrap them in functors.


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

* Re: [Caml-list] mutually recursive modules
  2008-03-22 21:20   ` ketti
@ 2008-03-23 16:59     ` Jacques Le Normand
  2008-03-23 18:37       ` ketti
  0 siblings, 1 reply; 7+ messages in thread
From: Jacques Le Normand @ 2008-03-23 16:59 UTC (permalink / raw)
  To: caml-list caml-list

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

how would I do that?

On Sat, Mar 22, 2008 at 5:20 PM, ketti <kattlachan@gmail.com> wrote:

> >  > is it possible to put mutually recursive modules in different files?
> >
> >  No.
>
> Yes.
> If you wrap them in functors.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

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

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

* Re: [Caml-list] mutually recursive modules
  2008-03-23 16:59     ` Jacques Le Normand
@ 2008-03-23 18:37       ` ketti
  2008-03-24  9:21         ` rossberg
  0 siblings, 1 reply; 7+ messages in thread
From: ketti @ 2008-03-23 18:37 UTC (permalink / raw)
  To: Jacques Le Normand; +Cc: caml-list caml-list

2008/3/23 Jacques Le Normand <rathereasy@gmail.com>:
> how would I do that?
>

You have to factor out the types of the modules.
Lets say we have modules A and B which are mutually recursive.
A needs to know the signature of B and vise verse.

So we define the signatures somewhere visible to both A and B:

module type A_T = sig ... end
module type B_T = sig ... end

Now in A and B we can write something like this:

module MkA = functor (B: B_T) -> struct
  ...
end

And then we can tie it together in a third file:

module MkA = A.MkA
module MkB = B.MkB
module rec A : A_T = MkA(B)
and B : B_T = MkB(A)

Done. ^^ (unless i made mistakes)

Does someone know of a less cumbersome way?


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

* Re: [Caml-list] mutually recursive modules
  2008-03-23 18:37       ` ketti
@ 2008-03-24  9:21         ` rossberg
  0 siblings, 0 replies; 7+ messages in thread
From: rossberg @ 2008-03-24  9:21 UTC (permalink / raw)
  To: caml-list

"ketti" <kattlachan@gmail.com> wrote:
>
> You have to factor out the types of the modules.
> Lets say we have modules A and B which are mutually recursive.
> A needs to know the signature of B and vise verse.
>
> So we define the signatures somewhere visible to both A and B:
>
> module type A_T = sig ... end
> module type B_T = sig ... end

Note that this only works if the signatures themselves aren't mutually
recursive - which often is the case. Unfortunately, there is no solution
that works in the general case.

- Andreas



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

* mutually recursive modules
@ 2006-01-17  8:55 Brendan Miller
  0 siblings, 0 replies; 7+ 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] 7+ messages in thread

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

Thread overview: 7+ 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

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).