From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA31599; Wed, 19 Feb 2003 12:49:40 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA32045 for ; Wed, 19 Feb 2003 12:49:39 +0100 (MET) Received: from paille.inria.fr (paille.inria.fr [128.93.11.15]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h1JBncT12744 for ; Wed, 19 Feb 2003 12:49:38 +0100 (MET) Received: (from hirschow@localhost) by paille.inria.fr (8.11.6/8.11.6) id h1JBncn02736; Wed, 19 Feb 2003 11:49:38 GMT From: Tom Hirschowitz MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Message-ID: <15955.28498.491350.48269@paille.inria.fr> Date: Wed, 19 Feb 2003 11:49:38 +0000 To: caml-list@inria.fr Subject: [Caml-list] Pb with type constraints in module In-Reply-To: <15955.25572.723415.666471@paille.inria.fr> References: <3E49B9E1.3060106@univ-savoie.fr> <15955.25572.723415.666471@paille.inria.fr> X-Mailer: VM 6.97 under Emacs 21.2.1 Reply-To: tom.hirschowitz@inria.fr Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Better explanation: a typedecl is a type identifier, plus a declaration= , right? Now, how do you parse "S with type A.t =3D A | B"? Tom Hirschowitz writes: >=20 > I don't know of any formalization of these "with" contraints, but th= e > current meaning is that typexpr must be a type in the outer > environment. If the declaration "S with type t =3D typexpr" is writ= ten > in the environment E, typexpr must be a valid type in E (and thus > cannot refer to t). The constraint is then propagated through the > module type S. In fact, "t" here is not exactly considered a type > identifier, but rather an access path into the constrained module > type. So, any reference to t in typexpr is considered a reference t= o > an upper definition of t, contrarily to what is done in type > declarations. >=20 > Therefore, you example is not correct in this setting, since the > references to t are wrong. It should not be too difficult to allow > datatype declarations though, while preserving this semantics, by > having a function for scoping datatypes non-recursively. I am not su= re > about the gain of expressive power though, since for instance your > example would remain incorrect. >=20 > Last remark: "with" constraints do propagate datatype > declarations, as soon as you use modules instead of types. >=20 > For example: >=20 > # module A =3D struct type t =3D A | B of t end;; > # module type T =3D sig module A : sig type t end end;; >=20 > # module type T' =3D T with module A =3D A;; > module type T' =3D sig module A : sig type t =3D A.t =3D A | B of t = end end >=20 >=20 > Cheers. >=20 > Christophe Raffalli writes: > >=20 > > Is there a good reason to have this in the grammar > > mod-constraint ::=3D > > type [type-parameters] typeconstr =3D typexpr > > | module module-path =3D extended-module-path > >=20 > > instead of > > mod-constraint ::=3D > > type typedef > > | module module-path =3D extended-module-path > >=20 > > Here is an example where this is useful: > >=20 > > Lets say you have a nice module type and functor: > >=20 > > -- > > module type Ord =3D > > sig > > =09type t > > =09val compare : t -> t -> int > > end > >=20 > > module F(G:Ord) =3D > > struct > > =09type t =3D Empty | Node of G.t * t * t > > =09let compare =3D ... the code you want ... > > end > > -- > >=20 > > in a .mli you may want to write > >=20 > > -- > > module F : functor (G:Ord) -> Ord > > with type t =3D Empty | Node of G.t * t * t > > -- > >=20 > > And this is not legal because "with type" take a typeexpr and not= a=20 > > typedef. This is not very natural, bacause you have to move the=20= > > definition of t outside F like in > > -- > > type 'a tree =3D Empty | Node of 'a * 'a tree * 'a tree > > module F(G:Ord) =3D > > struct > > =09type t =3D G.t tree > > =09let compare =3D ... the code you want ... > > end > > -- > >=20 > > in a .mli you can now write > > -- > > type 'a tree =3D Empty | Node of 'a * 'a tree * 'a tree > > module F : functor (G:Ord) -> Ord with type t =3D G.t tree > > -- > >=20 > > The same happends if you use recursive type > > -- > > module F : functor (G:Ord) -> Ord with type t =3D (G.t * t) list > > -- > > is not legal either. > >=20 > > --=20 > > Christophe Raffalli > > Universit=E9 de Savoie > > Batiment Le Chablais, bureau 21 > > 73376 Le Bourget-du-Lac Cedex > >=20 > > t=E9l: (33) 4 79 75 81 03 > > fax: (33) 4 79 75 87 42 > > mail: Christophe.Raffalli@univ-savoie.fr > > www: http://www.lama.univ-savoie.fr/~RAFFALLI > > --------------------------------------------- > > IMPORTANT: this mail is signed using PGP/MIME > > At least Enigmail/Mozilla, mutt or evolution > > can check this signature > > --------------------------------------------- > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://cam= l.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inr= ia.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >=20 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners