Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Type abstraction question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-24 (12:25)
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 =
     type t
     type bin_t = t -> t -> t
     val add : bin_t
     val sub : bin_t

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 ) ->
     val op : (A.t * A.t) -> (A.t * A.t) -> (A.t * A.t)

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...



To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: