From: Norman Ramsey <nr@eecs.harvard.edu>
To: caml-list@inria.fr
Cc: avi@labrador.eecs.harvard.edu, nr@labrador.eecs.harvard.edu
Subject: help wanted with recursive types across module boundaries
Date: Thu, 10 Aug 2000 13:13:06 -0400 [thread overview]
Message-ID: <200008101713.NAA18938@labrador.eecs.harvard.edu> (raw)
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
next reply other threads:[~2000-08-11 8:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-08-10 17:13 Norman Ramsey [this message]
2000-08-11 15:14 ` Thorsten Ohl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200008101713.NAA18938@labrador.eecs.harvard.edu \
--to=nr@eecs.harvard.edu \
--cc=avi@labrador.eecs.harvard.edu \
--cc=caml-list@inria.fr \
--cc=nr@labrador.eecs.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox