Browse thread
Shared types: dependency in modules with polymorphic type
[
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: | Hugo Ferreira <hmf@i...> |
| Subject: | Shared types: dependency in modules with polymorphic type |
Hello,
I have had to parametrize several modules
an am now having trouble using these interfaces.
I have the following situation:
The following signatures and module are a
generic data container. I want to use
this container in another module.
module type VB = sig
type 'a t
val empty : 'a t
val add : 'a t -> 'a -> 'a t
end
module VB1 : VB
= struct
type 'a t = 'a list
let empty = []
let add l e = e :: l
end
The following interface and module use the
generic container. It also stipulates what
type will be used in the polymorphic type.
module type U =
sig
type instance = int
type t
val zero : instance
val one : instance
val empty : t
val do_something : t -> instance -> t
end
module Make_U (Vb : VB) : U
= struct
type instance = int
type t = instance Vb.t
let zero = 0
let one = 1
let empty = Vb.empty
let do_something ts inst = Vb.add ts inst
end
module U1 = Make_U ( VB1 )
If I use and access all U1's elements
via its interface I have no problems.
However I need to use VB1 to access and
manipulate the U1.t set in order to
manipulate U1.instance types so...
let _ =
(*
let vb0 = VB1.empty in
let vb1 = VB1.add vb0 U1.zero in *)
let vb1 = U1.empty in
let vb2 = U1.do_something vb1 U1.one in
let vb3 = VB1.add vb2 U1.zero in
()
I get errors: all uses of Vb1.t fail. For example
using the first two lines and commenting the
third I get the error:
This expression has type U1.instance VB1.t but is here used with type
U1.t = Make_U(VB1).t
vb1: U1.instance VB1.t
Or in the case above as is, I get:
This expression has type U1.t = Make_U(VB1).t but is here used with type
'a VB1.t
vb2: U1.t
My question is: is their any way I may organize the modules or
indicate shared types in order to use a (very extensive) VB
interface (Or VB1 module)? Specifically how do I enforce the
shared type:
U1.instance VB1.t = U1.t = Make_U(VB1).t
TIA,
Hugo F.