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 TAA00828; Thu, 28 Nov 2002 19:51:35 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 TAA00569 for ; Thu, 28 Nov 2002 19:51:35 +0100 (MET) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gASIpY124931 for ; Thu, 28 Nov 2002 19:51:34 +0100 (MET) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id gASIpYB33057 ; Thu, 28 Nov 2002 19:51:34 +0100 (CET) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.12.3/jb-1.1) id gASIpXVx020707 ; Thu, 28 Nov 2002 19:51:33 +0100 (MET) Date: Thu, 28 Nov 2002 19:51:33 +0100 (MET) From: Alain Frisch To: Martin Jambon cc: caml-list@inria.fr Subject: Re: [Caml-list] Type aliases In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-milter (http://amavis.org/) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 28 Nov 2002, Martin Jambon wrote: > 1) Define type aliases: ... > 2) Don't hide their representation and derive the primitives from the > original type: ... > 3) Prohibit the mixing of different types that do not derive from each > other, without an explicit cast: ... > Basically, I would like to minimize the risk of error when I manipulate > simple datatypes like numerical parameters or int/string identifiers. You can get something close to what you want with: module Ints : sig type 'a integer val int: int -> 'a integer val get: 'a integer -> int val ( + ): 'a integer -> 'a integer -> 'a integer val ( * ): 'a integer -> 'a integer -> 'a integer (* etc... *) end = struct type 'a integer = int let int x = x let get x = x include Pervasives end integer literals must be written like (int 42), which is somewhat painful, but Camlp4 can help here... The point is that you cannot mix Apples and Oranges: # open Ints;; # let x : [ `Apple ] integer = int 3;; val x : [ `Apple] Ints.integer = # let y : [ `Orange ] integer = int 4;; val y : [ `Orange] Ints.integer = # get (x + y);; This expression has type [ `Orange] Ints.integer but is here used with type [ `Apple] Ints.integer Hope this helps. -- Alain ------------------- 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