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 TAA00902; Thu, 28 Nov 2002 19:54:52 +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 TAA00890 for ; Thu, 28 Nov 2002 19:54:51 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (host145-68.pool80116.interbusiness.it [80.116.68.145]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gASIsoX09123 for ; Thu, 28 Nov 2002 19:54:50 +0100 (MET) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 72DCF273E5; Thu, 28 Nov 2002 19:55:41 +0100 (CET) Message-ID: <3DE666AD.9000705@baretta.com> Date: Thu, 28 Nov 2002 19:55:41 +0100 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: Martin Jambon , ocaml Subject: Re: [Caml-list] Type aliases References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Martin Jambon wrote: > 3) Prohibit the mixing of different types that do not derive from each > other, without an explicit cast: > > let my_mistake = year + month (* Type error! *) > > where year has type year and month has type month. > But this could be valid: > > let some_int = (year :> int) * 13 + month > When I want this kind of property I use variant tags to encapsulate the datum and document its semantics: type time_value = [ | `Year of int | `Month of int | `Week of int | `Day of int | `Hour of int | `Min of int | `Sec of int ] let this_year = `Year(2002) let time_value_function = function | `Year (y) -> ... | `Month(m) -> ... ... This is a fairly heavy solution in terms of code length, but it does guarantee type safety and excellent level of readability--a property you'd lose with operator overloading. Alex ------------------- 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