From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA18579 for caml-redistribution; Wed, 27 Jan 1999 19:27:06 +0100 (MET) 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 TAA12592 for ; Tue, 26 Jan 1999 19:51:59 +0100 (MET) Received: from mail.nap.com.ar (mail.nap.com.ar [209.14.116.11]) by nez-perce.inria.fr (8.8.7/8.8.7) with SMTP id TAA27429 for ; Tue, 26 Jan 1999 19:51:57 +0100 (MET) Received: from [209.14.117.161] (HELO k-bell.com) by mail.nap.com.ar (Stalker SMTP Server 1.7) with ESMTP id S.0000595627 for ; Tue, 26 Jan 1999 15:51:59 -0300 Message-ID: <36AE0E34.6BF3A367@k-bell.com> Date: Tue, 26 Jan 1999 15:49:28 -0300 From: =?iso-8859-1?Q?Mat=EDas?= Giovannini Reply-To: matias@k-bell.com Organization: Script S.A. X-Mailer: Mozilla 4.5 (Macintosh; I; PPC) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Q] Multiple patterns in O'Caml Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: weis Hi, people. I was wondering about multiple pattern matching using fun. Why is that, compared to Caml Light, fun (unlike function) permits only one pattern to be matched? I'd think that, since type constructors and variables are in different namespaces now, there would be no (syntactic) need for separate keywords function and fun (as was true of Caml Light: fun couldn't distinguish between a type constructor and a variable starting with an uppercase letter in a pattern, hence it required every pattern to be parenthesized to avoid ambiguities), and that fun could subsume the multiple-branch, multiple-pattern of yore with the same elegant (and parentheses-sparing) syntax of function. Because, you see, I realize that the only way (other than to nest match'es, or function's) to match multiple patterns is to use a tuple, like this: (* In Caml Light *) let rec drop = fun | 0 l -> l | n [] -> failwith "drop" | n (a::x) -> drop (pred n) x ;; (* In O'Caml *) let rec drop n l = match (n,l) with | 0,l -> l | n,[] -> failwith "drop" | n,a::x -> drop (pred n) x ;; but this requires an extraneous tuple construction and its subsequent destruction, and kinda seems wasteful to me. Thank you in advance, best regards Matías.