caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Hugo Ferreira <hmf@inescporto.pt>
To: caml-list@yquem.inria.fr
Subject: Shared types: dependency in modules with polymorphic type
Date: Wed, 13 May 2009 20:12:01 +0100	[thread overview]
Message-ID: <4A0B1B81.8090700@inescporto.pt> (raw)

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.





             reply	other threads:[~2009-05-13 19:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-13 19:12 Hugo Ferreira [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A0B1B81.8090700@inescporto.pt \
    --to=hmf@inescporto.pt \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).