* [Caml-list] Type abstraction question
@ 2003-10-24 12:25 Andrew Bagdanov
0 siblings, 0 replies; only message in thread
From: Andrew Bagdanov @ 2003-10-24 12:25 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-10-24 12:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-24 12:25 [Caml-list] Type abstraction question Andrew Bagdanov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox