Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* help wanted with recursive types across module boundaries
@ 2000-08-10 17:13 Norman Ramsey
  2000-08-11 15:14 ` Thorsten Ohl
  0 siblings, 1 reply; 2+ messages in thread
From: Norman Ramsey @ 2000-08-10 17:13 UTC (permalink / raw)
  To: caml-list; +Cc: avi, nr

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




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

end of thread, other threads:[~2000-08-14 16:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-10 17:13 help wanted with recursive types across module boundaries Norman Ramsey
2000-08-11 15:14 ` Thorsten Ohl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox