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 AAA15105; Thu, 24 Jul 2003 00:41:24 +0200 (MET DST) 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 AAA21433 for ; Thu, 24 Jul 2003 00:41:23 +0200 (MET DST) Received: from pyramid.twistedmatrix.com (adsl-64-123-27-105.dsl.austtx.swbell.net [64.123.27.105]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h6NMfMT19773 for ; Thu, 24 Jul 2003 00:41:22 +0200 (MET DST) Received: from chris by pyramid.twistedmatrix.com with local (Exim 3.35 #1 (Debian)) id 19fSIS-0004Gj-00 for ; Wed, 23 Jul 2003 17:41:20 -0500 Date: Wed, 23 Jul 2003 17:41:20 -0500 From: Chris Clearwater To: caml-list@inria.fr Subject: Re: [Caml-list] Functor implementation Message-ID: <20030723224120.GA10834@pyramid.twistedmatrix.com> References: <20030723115644.GA28291@pyramid.twistedmatrix.com> <20030723150132.A30456@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030723150132.A30456@pauillac.inria.fr> User-Agent: Mutt/1.3.28i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 functor:01 ahh:01 functors:01 helper:01 chris:01 bool:01 int:01 0200,:01 comparison:02 wrote:03 constructor:03 types:03 let:04 jul:06 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Jul 23, 2003 at 03:01:32PM +0200, Xavier Leroy wrote: > Now, let me warn you about the following code: > > > let compare x y = > let cmp = x - y in if cmp > 0 then GT else if cmp < 0 then LT else EQ > > which doesn't work if x and y are sufficiently far apart > (e.g. x = max_int and y = min_int). > > - Xavier Leroy Ahh, thanks, functors now fit nicely in my head. And yeah that cmp function was kind of braindead. I dont know why I didnt simply write it as : let cmp x y = if x > y then GT else if x < y then LT else EQ. But it would still be nice if the built in comparison function returned a sum type. And there was provided a helper function: let comparison_of_int x = if x > 0 then GT else if x < 0 then LT else EQ. Maybe "ordering" is a more appropriate name. Also, true and false appear to be a sum type: type bool = True | False, except you can't have lower case constructor names. Does this signal the fact that there is some kind of limitation with having primitive sum types? ------------------- 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