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 UAA03639; Wed, 18 Sep 2002 20:06:49 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA03265 for caml-list@pauillac.inria.fr; Wed, 18 Sep 2002 20:06:47 +0200 (MET DST) 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 RAA01637 for ; Tue, 17 Sep 2002 17:24:37 +0200 (MET DST) Received: from star2.baremetal.com (star2.baremetal.com [216.86.113.248]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8HFOa113318 for ; Tue, 17 Sep 2002 17:24:36 +0200 (MET DST) Received: from akiv48cdy59dc.bc.hsia.telus.net (akiv48cdy59dc.bc.hsia.telus.net [142.179.98.88] (may be forged)) by star2.baremetal.com (8.12.4/8.12.4) with ESMTP id g8HFRnKn032326; Tue, 17 Sep 2002 08:27:49 -0700 Date: Tue, 17 Sep 2002 08:23:01 -0700 Subject: Re: [Caml-list] function polymorphic in number of arguments? Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v543) Cc: Noel Welsh To: From: Quetzalcoatl Bradley In-Reply-To: <20020917084045.46976.qmail@web11206.mail.yahoo.com> Message-Id: <5AD3EB96-CA51-11D6-93E8-0030657680C6@blackfen.com> Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.543) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Actually I wanted to pass the same parameters to both g and h but your solution is obvious and simple. if all the arguments of g and h are curried then my generic function always has "one" argument, the tuple of arguments to g and h, regardless of the size of the tuple. So my function is let f a b x = a x; b x;; and a two argument "a" or "b" would be let a x = match x with (i,j) -> print_string ("i" ^ "j");; and I can call it e.g. f a a ("z","x");; Thanks, Quetzalcoatl Bradley qbradley@blackfen.com On Tuesday, September 17, 2002, at 01:40 AM, Noel Welsh wrote: > You can't have multiple arity functions or tuples in > O'Caml, but you can curry the functions before calling > them which is how I'd solve your problem. You want to > write something like: > > fun f g h a1 a2 b1 b2 = > g a1 a2 ; h b1 b2 > > with varying numbers of a and b. Instead you can > write: > > > fun f g h a1 b1 = > g a1; h b1 > > and curry additional parameters when you call the > function: > > f (g a2) (h a2) > > This gets the same effect. Alternatively you can use > Scheme/Lisp which supports varying arity functions and > has a handy apply function, for applying varying > numbers of arguments to a function. > > Noel > --- Quetzalcoatl Bradley > wrote: >> Suppose all the parameters were curried. Unless I >> could operate on >> tuples like they were lists then I would still be in >> the same boat. I >> suppose if there was a tuple->list conversion >> function I could achieve >> the effect I desire. Is there such an operation? >> >> Thanks, >> >> Quetzalcoatl Bradley >> qbradley@newheights.com > > > __________________________________________________ > Do you Yahoo!? > Yahoo! News - Today's headlines > http://news.yahoo.com > ------------------- 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