Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Thierry Bravier <thierry.bravier@dassault-aviation.fr>
To: caml-list@inria.fr
Subject: Re: Objective Caml 2.00 released
Date: Thu, 27 Aug 1998 14:22:29 +0200	[thread overview]
Message-ID: <35E54F85.6774@dassault-aviation.fr> (raw)
In-Reply-To: <19980819102602.39105@pauillac.inria.fr>

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 = <module-expr> in <expr>".

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





      reply	other threads:[~1998-08-27 17:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-19  8:26 Xavier Leroy
1998-08-27 12:22 ` Thierry Bravier [this message]

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=35E54F85.6774@dassault-aviation.fr \
    --to=thierry.bravier@dassault-aviation.fr \
    --cc=caml-list@inria.fr \
    /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