From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA14276 for caml-red; Mon, 14 Aug 2000 18:47:09 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA20250 for ; Fri, 11 Aug 2000 17:13:36 +0200 (MET DST) Received: from heplix4.ikp.physik.tu-darmstadt.de (heplix4.ikp.physik.tu-darmstadt.de [130.83.24.139]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e7BFDZj28034 for ; Fri, 11 Aug 2000 17:13:35 +0200 (MET DST) Received: (from ohl@localhost) by heplix4.ikp.physik.tu-darmstadt.de (8.9.3/8.9.3) id RAA26317; Fri, 11 Aug 2000 17:14:01 +0200 X-Authentication-Warning: heplix4.ikp.physik.tu-darmstadt.de: ohl set sender to ohl@heplix4.ikp.physik.tu-darmstadt.de using -f From: Thorsten Ohl Message-ID: <14740.6201.936205.643362@heplix4.ikp.physik.tu-darmstadt.de> Date: Fri, 11 Aug 2000 17:14:01 +0200 (CEST) To: caml-list@inria.fr Cc: Norman Ramsey Subject: help wanted with recursive types across module boundaries In-Reply-To: <200008101713.NAA18938@labrador.eecs.harvard.edu> References: <200008101713.NAA18938@labrador.eecs.harvard.edu> X-Mailer: VM 6.74 under Emacs 20.3.1 Reply-To: ohl@hep.tu-darmstadt.de Sender: weis@pauillac.inria.fr > If I were writing Standard ML, I would attempt the following: > > module type ValueDist = sig > include Dist > type v' = V of dist Value.v > sharing type v = v' > end AFAIK, there is no `sharing' keyword in O'Caml, but you should be able to use the `with' operator instead: module type Dist = sig type v type dist end module Value = struct type name type 'vdist v = Int of int | Record of (name * 'vdist v) list | Function of ('vdist v -> 'vdist) end (* If the implementation were absent, one could not refer to Dist.dist below. Strangely enough, placing Dist in a separate dist.mli file (w/o a dist.ml) would work. I've never understood the reason for this behavior ... *) module Dist : Dist = struct type v type dist end type vdv = V of Dist.dist Value.v module type ValueDist = sig include Dist type v' = vdv end with type v = vdv At least it compiles and if type equivalence is transitive, it should do the right thing: ohl@heplix4:~tmp$ ocamlc -i -c nr.ml module type Dist = sig type v and dist end module Value : sig type name and 'a v = Int of int | Record of (name * 'a v) list | Function of ('a v -> 'a) end module Dist : Dist type vdv = V of Dist.dist Value.v module type ValueDist = sig type v = vdv and dist and v' = vdv end Cheers, -Thorsten -- Thorsten Ohl, Physics Department, TU Darmstadt -- ohl@hep.tu-darmstadt.de http://heplix.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here]