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 KAA12708 for caml-red; Fri, 11 Aug 2000 10:09:28 +0200 (MET DST) 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 TAA06438 for ; Thu, 10 Aug 2000 19:13:17 +0200 (MET DST) Received: from labrador.eecs.harvard.edu (labrador.eecs.harvard.edu [140.247.60.247]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e7AHDG523165 for ; Thu, 10 Aug 2000 19:13:16 +0200 (MET DST) Received: (from nr@localhost) by labrador.eecs.harvard.edu (8.9.3/8.9.3) id NAA18938; Thu, 10 Aug 2000 13:13:06 -0400 Date: Thu, 10 Aug 2000 13:13:06 -0400 From: Norman Ramsey Message-Id: <200008101713.NAA18938@labrador.eecs.harvard.edu> To: caml-list@inria.fr Subject: help wanted with recursive types across module boundaries Cc: avi@labrador.eecs.harvard.edu, nr@labrador.eecs.harvard.edu Sender: weis@pauillac.inria.fr I'm having trouble breaking a recursion that crosses module boundaries. I have a representation of probability distributions. Ordinarily I would use a monad, declaring type 'a dist, with unit, bind, and other operations, but I want (among other implementations) an efficient implementations in terms of sets, so polymorphism is not indicated. I therefore have module type Dist = sig type v (* values *) type dist (* probability distribution over values *) val unit : v -> dist val bind : dist -> (v -> dist) -> dist ... end Of the values in which I am interested, one kind of value is a function from values to probability distributions over values. module Value = struct type 'vdist v = Int of int | Record of (name * 'vdist v) list | Function of ('vdist v -> 'vdist) end Now I want to close the loop. 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 (I enclose the equivalent Standard ML code below, which compiles.) I want to write a functor that takes ValueDist as an argument. How can I do this in OCaml? Norman (* type-correct standard ml code follows *) signature Dist = sig type v (* values *) type dist (* probability distribution over values *) val unit : v -> dist val bind : dist -> (v -> dist) -> dist end structure Value = struct datatype 'vdist v = Int of int | Record of (string * 'vdist v) list | Function of ('vdist v -> 'vdist) end signature ValueDist = sig include Dist datatype v' = V of dist Value.v sharing type v = v' end