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 XAA20311; Sat, 30 Jun 2001 23:00:08 +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 XAA20374 for ; Sat, 30 Jun 2001 23:00:07 +0200 (MET DST) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f5UL06H12742; Sat, 30 Jun 2001 23:00:06 +0200 (MET DST) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id NAA20467; Sat, 30 Jun 2001 13:59:05 -0700 (PDT) Date: Sat, 30 Jun 2001 13:59:05 -0700 (PDT) From: Brian Rogoff To: Patrick M Doane cc: John Max Skaller , Jun Furuse , caml-list@inria.fr Subject: Re: "Re: [Caml-list] A G'Caml question" + additional info In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, 30 Jun 2001, Patrick M Doane wrote: > On Sat, 30 Jun 2001, John Max Skaller wrote: > > G'caml makes it easier to write readable algorithms, > > and to do 'cut and paste' genericity. But it can't do what > > you can do in C++. > I agree. Although I'm not advocating that it do everything you can do in > C++. Less talk, more coding examples please. GCaml polymorphism is remarkably easy to use. A while ago, when there was some discussion of overloading on the list, Pierre Weis mentioned that he'd like a style of overloading that would allow us to overload array access, string access, and hashtbl access. How easy is that? Well, it writes itself from that sentence generic get = case | string -> int -> char => String.get | $a array -> int -> $a => Array.get | $a list -> int -> $a => List.nth | ($a,$b) Hashtbl.t -> $a -> $b => Hashtbl.find | ($a -> $b) -> $a -> $b => fun f -> f;; OK, I'd like a bit of syntax sugar to make this .(), but that generic does the trick, and then some (it works with a single argument function too). This extensional polymorphism is beautiful, as well as practical. One of the nice things about the STL is the way that it allows you to write the algorithms independently of the containers, using the iterator interfaces. You can write functions over generics like "get" to achieve the same effect in GCaml. > > > The proposed 'include' feature makes it much easier to > > > extend generic values, but doesn't help with derived generics. How doesn't it help? > > Objects can help, but really that isn't the answer. > > The answer is more like: what can we do to make C++ like > > generics properly parametric? > > > > It is possible to make STL like algorithms in Ocaml now. > > The problem is that you have to pass in a LOT of data, such as > > functions to deref and increment the iterator. > > I think that one can implement much of the STL algorithms in the Caml > object system (avoiding the need to pass lots of data). While I think the STL is a fine design for a language like C++, I'm not sure that STL emulation is high on my list of criteria for an OCaml overloading extension. Once that include feature is in *and* it is integrated with the rest of the type system (modules and signatures, classes, polymorphic variants, etc.) we'll have an enormous amount of power. -- Brian ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr