From: Andrew Bagdanov <andrew@science.uva.nl>
To: caml-list@pauillac.inria.fr
Subject: [Caml-list] Type abstraction question
Date: Fri, 24 Oct 2003 14:25:07 +0200 [thread overview]
Message-ID: <16281.6691.677366.101886@vegas.science.uva.nl> (raw)
Hello all,
I'm having a bit of difficulty getting the sort of type abstraction
I want.
I have the following sort of module:
module type Alg =
sig
type t
type bin_t = t -> t -> t
val add : bin_t
val sub : bin_t
end
which just encapsulates a domain and a few operations that can be
performed over values. What I want to do is expose the type "t" but
_not_ "bin_t" to the world. The specific reason I want this is so
that people can only apply functors like the following:
module PairLifter :
functor ( A : Alg ) ->
functor ( Op : sig val op : A.bin_t end ) ->
sig
val op : (A.t * A.t) -> (A.t * A.t) -> (A.t * A.t)
end
with operations explicitly defined in implementations of type Alg.
That is, assuming there is an implementation of:
module IntAlg : Alg with type t = int
then I want:
module PairAdd = PairLifter(IntAlg)(struct let op = IntAlg.add end)
to work fine, but:
module PairAdd = PairLifter(IntAlg)(struct let op = ( + ) end)
to fail. It is somewhat crucial for the type "t" to be exposed,
however, to simplify passing of constants, etc.
Anyway, this is a simplified version of what I'm trying to do, and I
fear there might be fundamental problems with my understanding of the
type system. So, feel free to hold my hand...
Thanks,
-Andy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
reply other threads:[~2003-10-24 12:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=16281.6691.677366.101886@vegas.science.uva.nl \
--to=andrew@science.uva.nl \
--cc=caml-list@pauillac.inria.fr \
/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