caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Shared types: dependency in modules with polymorphic type
@ 2009-05-13 19:12 Hugo Ferreira
  2009-05-13 19:40 ` [Caml-list] " Jacques Carette
  0 siblings, 1 reply; 10+ messages in thread
From: Hugo Ferreira @ 2009-05-13 19:12 UTC (permalink / raw)
  To: caml-list

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.





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-05-14 15:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-13 19:12 Shared types: dependency in modules with polymorphic type Hugo Ferreira
2009-05-13 19:40 ` [Caml-list] " Jacques Carette
2009-05-14  7:58   ` Hugo Ferreira
2009-05-14 14:42     ` Andreas Rossberg
2009-05-14 15:06       ` Hugo Ferreira
2009-05-14 11:41   ` Shared types: circular " Hugo Ferreira
2009-05-14 12:11     ` [Caml-list] " Peng Zang
2009-05-14 12:46       ` Hugo Ferreira
2009-05-14 13:20         ` Peng Zang
2009-05-14 13:28           ` Hugo Ferreira

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).