From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id C76CABB9C for ; Tue, 17 Jan 2006 11:21:53 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0HALrG1027885 for ; Tue, 17 Jan 2006 11:21:53 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA23506 for ; Tue, 17 Jan 2006 11:21:52 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0HALo9o016523 for ; Tue, 17 Jan 2006 11:21:51 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id k0HALkTm021877; Tue, 17 Jan 2006 19:21:46 +0900 (JST) Date: Tue, 17 Jan 2006 19:21:44 +0900 (JST) Message-Id: <20060117.192144.95936185.garrigue@math.nagoya-u.ac.jp> To: catphive.lists@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] mutually recursive modules From: Jacques Garrigue In-Reply-To: <3dd983220601170055w5bd95adfjca47847809f3226e@mail.gmail.com> References: <3dd983220601170055w5bd95adfjca47847809f3226e@mail.gmail.com> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 43CCC541.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43CCC53E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 recursive:01 ocaml:01 ocaml:01 compiler:01 dependancy:01 initialized:01 iirc:01 recursion:01 syntax:01 recursion:01 brendan:98 arbitrary:01 simpler:01 interfaces:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: Brendan Miller > 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? In ocaml modules do not only define functions, but also values. It means that they require computation at initialization time. If two modules recurse with each other, which one should be initialized first? What happens when one accesses an uninitialized value? C has one answer: no initialization in modules, and (IIRC) random values when unitialized. Java has another answer: somewhat arbitrary initialization order, and each type has a default value. In ocaml initialization happens, and there are no default values, so there is no good answer to what should happen with mutual recursion. So this is prohibited. > 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. Yes, you can define interfaces with "class type". Since class types are "structural", i.e. two identical definitions in different places are seen as equal, this allows recursion at the type level. However, other type definitions (like sums and records) are not structural, so you cannot move them around. So most people just define all their exported types in a single module, which can be seen by all the program. You can avoid it, but this makes life simpler. Jacques