caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Peng Zang <peng.zang@gmail.com>
To: caml-list@yquem.inria.fr
Cc: Hugo Ferreira <hmf@inescporto.pt>
Subject: Re: [Caml-list] Shared types: circular dependency in modules with polymorphic type
Date: Thu, 14 May 2009 08:11:50 -0400	[thread overview]
Message-ID: <200905140811.56572.peng.zang@gmail.com> (raw)
In-Reply-To: <4A0C0364.7000408@inescporto.pt>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I think this is because UI.t is abstract and is in fact, never created.  You 
need to tell the old caml that UI.t is actuall an int VI.t.  Then it should 
work.

module Make_P (VI : VB)
              (UI : U with type t = int VI.t)
              (RI : R with type t = UI.t and type instance = UI.instance ) =
struct ... end

module P1 = Make_P ( VB1 ) ( U1 ) ( R1 )

Works like a charm for me,

Peng


On Thursday 14 May 2009 07:41:24 am Hugo Ferreira wrote:
> Hello,
>
> I have again encountered a problem with sharing types.
> However this time I really have a set of interfaces
> which need to be "stitched" together via type sharing.
>
> Problem is I am dealing with a circular polymorphic
> type dependency. Or at least seems so. I have added the
> very simple code for testing at the end. But the short
> of it is: with the code below
>
> module Make_P (VI : VB)
>                (UI : U)
>                (RI : R with type t = UI.t )
> = struct
>
>    type instance = UI.instance
>    type t = UI.t
>
>    let do_something_nice null =
>      let vb0 = VI.empty in
>      let vb1 = VI.add vb0 UI.zero in
>      RI.do_something_else vb1 UI.one
>
> end
>
> I get the error:
>
> This expression (vb1) has type UI.instance VI.t but is here used with type
>    RI.t = UI.t
> vb1: UI.instance VI.t
>
>
> The problem is that VI.t is polymorphic.
> And UI uses VI.t setting the polymorphic
> type in the process.
> I want to make it "UI.instance VI.t."
> How can I do that. I have tried:
>
>
> module Make_P (VI : VB)
>                (UI : U with type t = U.instance VI.t)
>                (RI : R with type t = UI.t )
> and
>
> module Make_P (UI : U)
>                (VI : VB with type 'a t = UI.t)
>                (RI : R with type t = UI.t )
>
> with no success.
>
>
>
> --------------------- Code ---------------
>
>
>
> 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
>
>
> 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)
> = 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 )
>
> let _ =
>
>    let vb0 = VB1.empty in
>    let vb1 = VB1.add vb0 U1.zero in
>    let vb2 = U1.do_something vb1 U1.one in
>    let _ = VB1.add vb2 U1.zero in
>    ()
>
>
> module type R =
>    sig
>
>      type instance = int
>      type t
>
>      val do_something_else : t -> instance -> t
> end
>
> module Make_R (VI : VB)
>                (UI : U)
> = struct
>
>    type instance = UI.instance
>    type t = UI.t
>
>    let do_something_else ts inst = UI.do_something ts inst
>
> end
>
> module R1 = Make_R ( VB1 ) ( U1 )
>
>
> let _ =
>
>    let vb0 = VB1.empty in
>    let vb1 = VB1.add vb0 U1.zero in
>    let vb2 = R1.do_something_else vb1 U1.one in
>    let _ = VB1.add vb2 U1.zero in
>    ()
>
>
> module Make_P (VI : VB)
>                (UI : U)
>                (RI : R with type t = UI.t )
> = struct
>
>    type instance = UI.instance
>    type t = UI.t
>
>    let do_something_nice null =
>      let vb0 = VI.empty in
>      let vb1 = VI.add vb0 UI.zero in
>      RI.do_something_else vb1 UI.one
>
> end
>
> module P1 = Make_P ( U1 ) ( VB1 ) ( R1 )
>
> or
>
> module P1 = Make_P ( VB1 ) ( U1 ) ( R1 )
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFKDAqMfIRcEFL/JewRAikyAKDWuRFALodBLy5NqWJFBH4MDD5FdgCg0Q5J
U4I+34lrt7QjpkzQwZpztEE=
=VbUW
-----END PGP SIGNATURE-----


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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-13 19:12 Shared types: " 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     ` Peng Zang [this message]
2009-05-14 12:46       ` [Caml-list] " 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=200905140811.56572.peng.zang@gmail.com \
    --to=peng.zang@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=hmf@inescporto.pt \
    /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).