English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-12-31 (01:10)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] recmod
On Fri, 2004-12-31 at 09:38, Anastasia Gornostaeva wrote:

> Is it possible to compile such files?
> mod1.ml: 
> let get a =
>    if Mod2.mem a then 1 else 2
> mod2.ml:
> let mem a = List.mem a [1;2;3]
> let other () =
>    print_int (Mod1.get 5)

No. There is a new experimental feature which provides
some support for intra-module recursion,
but at present the modules must reside
in the same file.

The two common workaround for functions are:

(a) pass Mod2.get to Mod1.get as an argument

(b) create a reference in mod1.ml initialised to 
   fun (x:int) -> raise Not_found; 1

   and in mod2.ml store Mod2.get into it, call it in mod1.ml
   by first dereferencing it.

Another technique is to use classes, which automate
the late binding more safely.

John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net