Browse thread
[Caml-list] Type abstraction question
- Andrew Bagdanov
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Andrew Bagdanov <andrew@s...> |
| Subject: | [Caml-list] Type abstraction question |
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