From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id A71F2D45F for ; Tue, 25 Oct 2005 03:09:31 +0200 (CEST) Received: from ash25e.internode.on.net (ash25e.internode.on.net [203.16.214.182]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j9P19Tc0022866 for ; Tue, 25 Oct 2005 03:09:30 +0200 Received: from rosella (ppp14-90.lns2.syd7.internode.on.net [59.167.14.90]) by ash25e.internode.on.net (8.12.9/8.12.6) with ESMTP id j9P19KZL067238; Tue, 25 Oct 2005 10:39:20 +0930 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: Ant: [Caml-list] how to implement generic operators From: skaller To: Martin Chabr Cc: caml-list@yquem.inria.fr In-Reply-To: <20051024182654.24834.qmail@web26808.mail.ukl.yahoo.com> References: <20051024182654.24834.qmail@web26808.mail.ukl.yahoo.com> Content-Type: text/plain Date: Tue, 25 Oct 2005 11:09:20 +1000 Message-Id: <1130202560.18325.21.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 435D85C9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 iter:01 overloading:01 ocaml:01 iter:01 elts:01 elt:01 seq:01 elt:01 nop:01 elts:01 overloading:01 compiler:01 subset:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Mon, 2005-10-24 at 20:26 +0200, Martin Chabr wrote: > I was surprised at first when I found out how OCaml > restricts lists. > Now I got used to it and appreciate the clarity: types > in mixed expressions must always be converted to be > compatible with each other. No automatic conversion > where you wonder what will happen. > C# had collections of mixed types as well in the 1.x > version. Now, in the version 2.0 they have generics > and strong type checking and everybody seems to like > it, not having to do any type detection and casting. The idea is to provide 'manifest' heterogeneity like this: iter print (1,2.0,"Hello"); which of course is just sugar for print 1; print 2.0; print "Hello"; This will work in Felix because it supports overloading. There is no loss of type safety, since each of the 3 generated terms is independently type checked. Internally, the Ocaml representation would be something like Iter (print, [1;2.0;"Hello"]) and the reduction rule would be something like: function | Iter (op, elts) -> fold_left (fun (result, elt) -> seq (result, op elt)) nop elts So basically this operation is just sugar which takes advantage of 'ad hoc polymorphism' aka overloading to allow the user to get 'free' nary operators. Note that the second argument to 'iter', namely (1,2.0, "hello"), is a *tuple*. It is therefore heterogenous automatically, but of fixed length. In Ocaml the *representation* is a list of terms, all of the same type, namely 'expression'. What I wrote above using Iter variant will work just fine. The problem is, I also need Compose, Ravel, ... and many MANY others. There are far too many to encode all of them in the compiler: a reasonable fixed subset will remain both incomplete and a lot of work to encode. So instead of encoding them all in the compiler, I want to encode them in the standard library, parse them, and write an interpreter in Ocaml to 'execute' the parsed encodings. See Jacques Carette post and my response for more. -- John Skaller Felix, successor to C++: http://felix.sf.net