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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id B1921D45F for ; Mon, 24 Oct 2005 21:27:43 +0200 (CEST) Received: from cgpsrv2.cis.mcmaster.ca (univmail.CIS.mcmaster.ca [130.113.64.46]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j9OJRgQs011244 for ; Mon, 24 Oct 2005 21:27:43 +0200 Received: from [130.113.68.27] (account carette@univmail.cis.mcmaster.ca [130.113.68.27] verified) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro SMTP 4.1.8) with ESMTP id 107527646; Mon, 24 Oct 2005 15:27:41 -0400 Message-ID: <435D35B7.2080905@mcmaster.ca> Date: Mon, 24 Oct 2005 15:27:51 -0400 From: Jacques Carette User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: skaller Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] how to implement generic operators References: <1130131250.28443.79.camel@rosella> In-Reply-To: <1130131250.28443.79.camel@rosella> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 435D35AE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 binary:01 binary:01 subset:01 ocaml:01 parsing:01 variants:01 metaocaml:01 staging:01 ...:98 lambda:01 wrote:01 evaluator:01 jacques:01 jacques: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 skaller wrote: >I would clearly need some representation like: > > Assoc of op * term list > >and then some kind of fold which works for all different binary op, >where now 'op' is defined by the user. > >So crudely the question is: what is the representation of 'op' >required so the generic fold can create a wide class of >generic n-ary operations from binary ones? > > You really need your operations to be left-associative for that to make sense... But in my toy interpreter for a subset of Maple (written in Ocaml), I have type op = term -> term -> term * term and then in the eval() function for a term, a case | Assoc ((f,init), l) -> List.fold_left f init l f can be created from a term by applying a term-level lambda, so that when you ask for >Note the data for op will be obtained by parsing in the input >program, so cannot consist of just a fixed list of variants. > > that can be done too. >I have a feeling MetaOcaml can do this already. > > Yes and no. Yes, it can be done by staging a very finely crafted evaluator. But doing that is very, very difficult given the current state-of-the-art [typed PE for typed languages is hard]. Or merely difficult if you write everything CPS style. But it is most definitely not something you get right out of the box. Jacques C.