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 XAA30701; Fri, 23 May 2003 23:23:54 +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 XAA30666 for ; Fri, 23 May 2003 23:23:53 +0200 (MET DST) Received: from grace.speakeasy.org (grace.speakeasy.org [216.254.0.2]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id h4NLNqH28102 for ; Fri, 23 May 2003 23:23:52 +0200 (MET DST) Received: (qmail 17920 invoked by uid 36130); 23 May 2003 21:23:51 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 23 May 2003 21:23:51 -0000 Date: Fri, 23 May 2003 14:23:51 -0700 (PDT) From: brogoff@speakeasy.net To: Brian Hurt cc: "caml-list@inria.fr" Subject: Re: [Caml-list] Why are arithmetic functions not polymorph? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam: no; 0.00; brogoff:01 caml-list:01 generic:01 reorder:01 oftentimes:01 arbitrarily:01 inlined:01 inference:01 camlp:01 accessor:01 hashtbl:01 lookups:01 pierre:01 weis:01 generics:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 23 May 2003, Brian Hurt wrote: > On Fri, 23 May 2003 brogoff@speakeasy.net wrote: > OK. I'm reading the readme. First off, congratulations, you're dodging a > lot of the bullets that C++ didn't. > > Here's a question. Consider the following code: > > generic one = | int => 1 | float => 1.0 > > generic two = | int => 2 | float => 2.0 > > generic plus = | int -> int -> int = (+) > | float -> float -> float = (+.) > > plus one two;; > > What's the result? Is it the int 3, or the float 3.0? Syntax error ;-) Fixing that, the int 3. Like pattern matching, if the first matches, that wins. If you reorder, you can make it return float. > Another problem already arises with the generic (aka overloaded) > comparisons- you oftentimes need to arbitrarily specify types in order to > replace the expensive call to the generic compare with a much cheaper > inlined type-specific compare. If you start having to specify types a lot > more often, that reduces the advantage of having type inference. I don't see that as too much of a problem, but maybe with more experience my opinion will change. > > New operators are not sufficient, and SML is more powerful in it's ability to > > define new operators than OCaml (minus CamlP4) is. > > Yeah- I'd like to be able to define accessor operators somehow. Say being > able to define $[ ] as hashtbl lookups, so that h$[3] ==> Hashtbl.find h > 3. Pierre Weis alluded to this desire in an ealier discussion of generics. -- Brian ------------------- 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