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 XAA18991; Mon, 27 Sep 2004 23:34:53 +0200 (MET DST) 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 XAA19387 for ; Mon, 27 Sep 2004 23:34:51 +0200 (MET DST) Received: from hkn.eecs.berkeley.edu (hkn.EECS.Berkeley.EDU [128.32.47.228]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i8RLYomI010804 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 27 Sep 2004 23:34:51 +0200 Received: from dyoo (helo=localhost) by hkn.eecs.berkeley.edu with local-esmtp id 1CC38w-0006H6-00; Mon, 27 Sep 2004 14:34:46 -0700 Date: Mon, 27 Sep 2004 14:34:46 -0700 (PDT) From: Danny Yoo To: "Rafael 'Dido' Sevilla" cc: John Goerzen , Subject: Re: [Caml-list] Observations on OCaml vs. Haskell In-Reply-To: <20040927202449.GA548@imperium.ph> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 4158877A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; hkn:99 caml-list:01 observations:01 haskell:01 32,:01 constrain:01 operands:01 ocaml's:01 run-time:01 compiler:01 ints:01 ocaml:01 ocaml:01 int:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > I've written several functions that can work with a "number-like" > > type. I don't really care if I get an integer, Int32, Int64, float, > > or what But since these are all different types in OCaml, I am forced > > to care, right down to using +, +., or Int64.add to perform basic > > arithmetic. [text cut] > However, I do agree with you that the mess with OCaml having to add > totally different operators to do arithmetic for integral and floating > point types is a wart in what is otherwise an elegant language. The > compiler could very easily make the arithmetic operators polymorphic, > and constrain the operands to be of the same (numeric) type, and signal > an error if you attempt to, say, multiply an integer with a floating > point number without doing the proper conversion. The comparison operators '<' are polymorphic, but that does incur some performance cost. Richard Jones's wonderful tutorial on OCaml touches on this under "Polymorphic types": http://www.merjis.com/developers/ocaml_tutorial/ch11 He shows that: ;;; let max a b = if a > b then a else b in print_int (max 2 3) ;;; uses the polymorphic version of '>', even though the use of max here uses only ints. I think OCaml's arithmetic operators are monomophic to avoid the cost of polymorphism. > Unless there's something in the design of the type system that prevents > this from happening except at run-time...? I wonder if the Cartesian Product Algorithm might be applicable to OCaml. There's a paper about it here: http://research.sun.com/self/papers/cpa.html where it sounds like it might be able to attack this problem. I'd love to be able to use just one '+' operator, rather than remember '+' vs '+.' vs '+/'. *grin* ------------------- 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