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 KAA08671; Fri, 31 Aug 2001 10:58:06 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA08832 for ; Fri, 31 Aug 2001 10:58:05 +0200 (MET DST) Received: from adansonia.wanadoo.fr (smtp-rt-14.wanadoo.fr [193.252.19.224]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f7V8w5522903 for ; Fri, 31 Aug 2001 10:58:05 +0200 (MET DST) Received: from citronier.wanadoo.fr (193.252.19.222) by adansonia.wanadoo.fr; 31 Aug 2001 10:58:01 +0200 Received: from debian (195.6.76.52) by citronier.wanadoo.fr; 31 Aug 2001 10:57:36 +0200 Received: from moi by debian with local (Exim 3.32 #1 (Debian)) id 15ciqG-0001ca-00 for ; Fri, 31 Aug 2001 09:35:52 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] syntax for variable arity? References: <20010830144540.D31317@ip178.usw22.rb1.bel.nwlink.com> From: Remi VANICAT Date: 31 Aug 2001 09:35:52 +0200 In-Reply-To: <20010830144540.D31317@ip178.usw22.rb1.bel.nwlink.com> Message-ID: <87y9o0wujr.dlv@wanadoo.fr> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.104 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Michael Leary writes: > I want to write a function to abstract a series of functions with different > numbers of args like these two: > > let debug message = printf "Debug %s\n" message; fso > let debug_line start_angle start_radius end_angle end_radius = > printf "DebugLine %f %f %f %f\n" start_angle start_radius end_angle end_radius; > fso > > > I was thinking of: > > type command = > Debug > | Debug_line > | ... won't work : ocaml can't make a so easily function with different numbers of args. > > let com command _ = > match command with > | Debug -> > doit "some special format string" _ > | Debug_line -> > doit "other format string" _ > > let doit _ = printf _ ; fso (* fso defined elsewhere *) > > > let () = com Debug "debug message" > ... > let () = com Debug_line start_angle start_radius end_angle end_radius > > > I know _ matches any value(s??), but I'm not clear on how to use the > match elsewhere... am I close? Is there a better way to structure > this? _ match only one value, it's the same to do let f _ = something and let f x = sommething where x is not used the solution for your problem is something as : type command | Debug of string | Debugline of float * float * float * float let com command = begin match command with | Debug st -> printf "Debug %s\n" st | Debugline (start_angle, start_radius, end_angle, end_radius) -> printf "DebugLine %f %f %f %f\n" start_angle start_radius end_angle end_radius end; fso -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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