From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8K9Na1w018488 for ; Tue, 20 Sep 2011 11:23:38 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsIBAGpaeE7RVdQ2kGdsb2JhbABCmHaOUggUAQEBAQkJDQcUBCGBUwEBAQEDEgIsARsSDAMMBgULDQ0hIgERAQUBChIZEhCHWZdBCotBglyFUDuIbQIDBoZzBJNLjQM9g3A X-IronPort-AV: E=Sophos;i="4.68,410,1312149600"; d="scan'208";a="109700500" Received: from mail-vw0-f54.google.com ([209.85.212.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 20 Sep 2011 11:23:38 +0200 Received: by vws11 with SMTP id 11so978716vws.27 for ; Tue, 20 Sep 2011 02:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=+KpmlutFh0UAdWXsOs7HDFLZhJUAL6Sm5kqNj0VE+fQ=; b=m7gfLM/1xNKnSN8trOFgoSeOBe2tfoIUVxV4zkVfjdsdp0GPFS/IHZ/HEKgeH/mySM PkEijp3xKc19T1RhZQh4wQXQw1IP+NJ/CTDx1VWYiL6cEZdN5AfA1Gpfbw0qa9hHUuCw EXO7ZcpOJGWXJ9GyzxbFcagLZ7TAftMbyy5ZY= MIME-Version: 1.0 Received: by 10.52.108.40 with SMTP id hh8mr420211vdb.505.1316510616972; Tue, 20 Sep 2011 02:23:36 -0700 (PDT) Received: by 10.52.109.7 with HTTP; Tue, 20 Sep 2011 02:23:36 -0700 (PDT) In-Reply-To: <4E7856EE.3050903@lexifi.com> References: <4E7856EE.3050903@lexifi.com> Date: Tue, 20 Sep 2011 11:23:36 +0200 Message-ID: From: Jacques Le Normand To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p8K9Na1w018488 Subject: Re: [Caml-list] A limitation of "with type" declarations for first-class modules For all of you wondering how unification works with package types: (module Foo with type t1 = tau1 and type t2 = tau2 and ... and tn = taun) unifies with (module Foo' with type t1' = tau1' and type t2' = tau2' and ... and tn' = taun') if and only if n = n' and Foo = Foo' and t1 = t1' and t2 = t2' and ... and tau1 unifies with tau1' and tau2 unifies with tau2' ... and t1...tn are all abstract types in Foo Right now t1...tn are all strings, but they might as well be paths (which would give the behaviour you need) On Tue, Sep 20, 2011 at 11:03 AM, Alain Frisch wrote: > On 09/20/2011 03:36 AM, Yaron Minsky wrote: >> >> For some reason, 1st-class modules have more restrictive "with" syntax, >> which turns out to be a practical problem. >> >> The main constraint is that with constraints do not seem to be able to >> refer to sub-modules.  Consider the following code snippet: >> >>>     module type Foo = sig type t end >>>     module type Bar = sig module Foo : Foo end >>> >>>     (* compiles *) >>>     let g (type a) (m : (module Foo with type t = a)) = () >>> >>>     (* fails to compile with a syntax error *) >>>     let f (type a) (m : (module Bar with type Foo.t = a)) = () >> >> Of course, ordinary modules have no such constraint.  Any thoughts as to >> what is going on here, and whether it can be fixed? > > The important point is that package types (the ... in a type expression > (module ...) or in an expression (module M : ...)) are not module types. > Syntactically, they are indeed a subset of module types, but it is a strict > subset, and they obey different rules than module types. > > Package types live at the boundary between types and module types. In a > packing expression (module M : ...), the package type must produce a > well-typed module type. This is why you cannot write (module M : S with type > t = 'a), because "S with type t = 'a" is not a proper module type. But > (module S with type t = 'a) is a correct type. > > Package types must also support all operations on types, including equality, > unification, etc.  For instance, unifying (module S1 with type t = 'a) and > (module S2 with type t = 'b) is defined as checking than S1 and S2 are > equivalent paths and unifying 'a and 'b. The fact that a package type can > also be seen as a module type is nowhere used in this definition. (Of > course, one must be careful when defining equality of package types that it > does not allow to cast a module from one module type to an incompatible > one.) > > There is some flexibility in both the definition of admissible package types > and the definition of equality between package types. > > For instance, I don't see any problem or difficulty in your proposal of > allowing constraints on types nested in sub-modules (but this should be > checked carefully). Feel free to open a feature request for this! Similarly, > one could allow "with type t :=" constraints in addition to "with type t =". >  Is there a need for that?  One could also relax equality of package types > (module S1 with ...) and (module S2 with ...) by checking that S1 and S2 > expand to structurally equivalent module types (with the exact same ordering > between value components!). > > > > -- Alain > > -- > Caml-list mailing list.  Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >