From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA11991 for caml-redistribution; Thu, 27 Aug 1998 19:12:07 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA18857 for ; Thu, 27 Aug 1998 14:18:12 +0200 (MET DST) Received: from relay5.eunet.fr (relay5.eunet.fr [193.107.193.102]) by nez-perce.inria.fr (8.8.7/8.8.7) with SMTP id OAA05399 for ; Thu, 27 Aug 1998 14:18:10 +0200 (MET DST) Received: from relay2.eunet.fr by relay5.eunet.fr (5.65c8d/96.05.03) via EUnet-France id AA01534; Thu, 27 Aug 1998 14:18:13 +0200 (MET) Received: from dassav (dassav.dassault-aviation.fr [193.106.72.131]) by relay2.eunet.fr (8.8.5/8.8.5) with SMTP id OAA24169 for ; Thu, 27 Aug 1998 14:18:10 +0200 (MET DST) Received: from fnet-ia1.dassault-aviation.fr by dassav (5.x/SMI-SVR4) id AA28869; Thu, 27 Aug 1998 14:11:14 +0200 Received: from fnet-ia2.fnet-ia by fnet-ia1.dassault-aviation.fr (SMI-8.6/SMI-SVR4) id OAA10356; Thu, 27 Aug 1998 14:22:23 +0200 Received: from fnet-ia2 by fnet-ia2.fnet-ia (SMI-8.6/SMI-SVR4) id OAA14927; Thu, 27 Aug 1998 14:22:30 +0200 Sender: weis Message-Id: <35E54F85.6774@dassault-aviation.fr> Date: Thu, 27 Aug 1998 14:22:29 +0200 From: Thierry Bravier Organization: Dassault Aviation DGT/DPR/DESA X-Mailer: Mozilla 3.01Gold (X11; I; SunOS 5.5.1 sun4c) Mime-Version: 1.0 To: caml-list@inria.fr Subject: Re: Objective Caml 2.00 released References: <19980819102602.39105@pauillac.inria.fr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Xavier Leroy wrote: > > It is my pleasure to announce the release of Objective Caml 2.00. > > Objective Caml 2.00: > -------------------- > > * Language: > - Local module definitions "let module X = in ". Thank you and congratulations for this release. The local module feature is, I think, really fine and useful it will allow (in my case) a much bigger use of the module system. Here are a few suggestions for related issues. Of course, I might have neglected theoretically bad consequences of my suggestions. I would like to have opinions about the implied coding style and its usefulness in ocaml. Cheers. TYPE PARAMETERS SCOPE: (* ================================================================== *) let remove_duplicates_string comparison_fun = let module StringSet = Set.Make (struct type t = string let compare = comparison_fun end) in fun string_list -> StringSet.elements (List.fold_right StringSet.add string_list StringSet.empty) (* val remove_duplicates_string : (string -> string -> int) -> string list -> string list *) let remove_duplicates_string_std = remove_duplicates_string compare let _ = remove_duplicates_string_std ["a"; "b"; "a"; "c"] let _ = remove_duplicates_string_std ["a"; "c"] (* ================================================================== *) (* (* Next part will not compile with ocaml-2.00 but, in my opinion would be nicer/better code, if allowed. *) let remove_duplicates_any (comparison_fun : 'any -> 'any -> int) = let module AnySet = Set.Make (struct type t = 'any (* ocaml-2.00 error message is: "Unbound type parameter any" *) let compare = comparison_fun end) in fun any_list -> AnySet.elements (List.fold_right AnySet.add any_list AnySet.empty) (* val remove_duplicates_any : ('a -> 'a -> int) -> 'a list -> 'a list *) let remove_duplicates_any_std = remove_duplicates compare let _ = remove_duplicates_any_std ['a'; 'b'; 'a'] let _ = remove_duplicates_any_std ["Hello"; "World"] *) (* ================================================================== *) ANONYMOUS MODULES: (* ================================================================== *) module type CMP = sig type t val compare : t -> t -> int end (* ================================================================== *) module Lexico (C1 : CMP) (C2 : CMP with type t = C1.t) : (CMP with type t = C1.t) = struct type t = C1.t let compare x y = let compare1 = C1.compare x y in if compare1 != 0 then compare1 else C2.compare x y end (* ================================================================== *) let combine compare1 compare2 = let module L = Lexico (struct type t = int let compare = compare1 end) (struct type t = int let compare = compare2 end) in L.compare (* ================================================================== *) (* (* Next part will not compile with ocaml-2.00 but, in my opinion would be nicer/better code, if allowed. *) let combine_nicer compare1 compare2 = Lexico (struct type t = int let compare = compare1 end) (struct type t = int let compare = compare2 end).compare (* ocaml-2.00 error message is: "Syntax error" *) *) (* ================================================================== *) MODULES SCOPE: (* ================================================================== *) type nat = Z | S of nat let make_nat () = let module N = struct type t = nat let z = Z let s n = S n let rec int = function | Z -> 0 | S n -> succ (int n) end in (N.z, N.s, N.int) (* As it is make_nat is not very useful because construction and direct access to nat values through constructors Z and S is possible. *) (* ================================================================== *) (* (* Next part will not compile with ocaml-2.00 but, in my opinion would be nicer/better code, if allowed. *) let make_nat () = let module N = struct type t = Z | S of t let z = Z let s n = S n let rec int = function | Z -> 0 | S n -> succ (int n) end in (N.z, N.s, N.int) (* ocaml-2.00 error message is: This `let module' expression has type N.t * (N.t -> N.t) * (N.t -> int) In this type, the locally bound module name N escapes its scope *) (* What I would like here is getting an abstract type "make_nat.t" that could only be created and accessed through the offered interface functions, that is z, s and int *) *) (* ================================================================== *) -- Thierry Bravier Dassault Aviation - DGT / DPR / DESA 78, Quai Marcel Dassault F-92214 Saint-Cloud Cedex - France Telephone : (33) 01 47 11 53 07 Telecopie : (33) 01 47 11 52 83 E-Mail : mailto:thierry.bravier@dassault-aviation.fr