From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.8 required=5.0 tests=DNS_FROM_RFC_POST,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id E5E92BC37 for ; Thu, 14 May 2009 15:20:24 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj8CADi3C0rRVYT3m2dsb2JhbACNUYkPPwEBAQEBCAkKAgcPpzYIgQqQAwEDAQODfwWGIg X-IronPort-AV: E=Sophos;i="4.41,194,1241388000"; d="scan'208";a="26167371" Received: from an-out-0708.google.com ([209.85.132.247]) by mail2-smtp-roc.national.inria.fr with ESMTP; 14 May 2009 15:20:24 +0200 Received: by an-out-0708.google.com with SMTP id b38so513456ana.3 for ; Thu, 14 May 2009 06:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date :user-agent:cc:references:in-reply-to:content-type :content-transfer-encoding:content-disposition:message-id; bh=uRJ4SEj6Oawqbgf2ODzD5AM2PPVk9gK9c/bmIPk2BVI=; b=RR4b3HkQ85gBecmiM/m1/i/pecaxh42CJfDluZxZdx8l0uf7CFPudt7FiAb52BGuUX uOdRhvZbcmL1tIbgVdhBOvwEORovvXw0JPsg5vhKQT+m2godoXqrjkgMojcVFALzf/lX LwrbRB38Foz086aP4jzQGBshsEXP3zxLU7MD0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to :content-type:content-transfer-encoding:content-disposition :message-id; b=iWW91IIcEI2cr+dWhWVcwqZ482xbWMUOqHC35Mmgaq/kQ1XCxTwuPqCGfIGymEHTdP qEapqxSGnbgmtUEUw+H7uzNpH5T553PIliFVZHe3co9LTKG3j8pLdWH3/JxQ1x26cPM0 qGe3GsFFLnnZMUI3V+jvbSeRnKxxKr+I7ISuM= Received: by 10.100.123.12 with SMTP id v12mr2986839anc.21.1242307223084; Thu, 14 May 2009 06:20:23 -0700 (PDT) Received: from ?192.168.0.102? ([98.230.173.131]) by mx.google.com with ESMTPS id c1sm193496ana.7.2009.05.14.06.20.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 14 May 2009 06:20:22 -0700 (PDT) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Shared types: circular dependency in modules with polymorphic type Date: Thu, 14 May 2009 09:20:18 -0400 User-Agent: KMail/1.9.9 Cc: Hugo Ferreira References: <4A0B1B81.8090700@inescporto.pt> <200905140811.56572.peng.zang@gmail.com> <4A0C12C2.9030108@inescporto.pt> In-Reply-To: <4A0C12C2.9030108@inescporto.pt> Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200905140920.20787.peng.zang@gmail.com> X-Spam: no; 0.00; hash:01 struct:01 hash:01 doable:01 struct:01 sig:01 val:01 val:01 sig:01 beginner's:01 ocaml:01 bug:01 peng:98 peng:98 2009:98 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 You could try factoring the complicated type out of U.t and keep it abstract. All that was holding back your original solution from working was the fact that the type was defined in U and so couldn't be shared. Maybe something like: module Make_P (VI:VB) (T:COMPLEXTYPE) (UI:U with type instance = T.t and type t = T.t VI.t) (RI:R with type instance = UI.instance and type t = UI.t) struct .. end Peng On Thursday 14 May 2009 08:46:58 am Hugo Ferreira wrote: > Hello, > > Appreciate the feedback. > > Peng Zang wrote: > > -----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. > > True. However in the real case I am not dealing with an "int" > but some more complicated data defined in U. I wanted to avoid > "looking" into U to know what U.t is and therefore set VI.t > accordingly. > > This is important because I will use different U implementations. > For each such cases I would have to create a module for each U > implementation. Not doable. > > > 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, > > I guess I will have to rethink my modules/types 8-(. > > Thanks, > Hugo F. > > > 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----- -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFKDBqUfIRcEFL/JewRAoVtAKCiNVC/v1+qBaKPUZxZrMzHsOKfpACfQdoI CJ4kV/JL6HCcrwVAYYluY9s= =HTzi -----END PGP SIGNATURE-----