From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA24399 for caml-redistribution; Thu, 14 Nov 1996 10:31:10 +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 VAA16161 for ; Wed, 13 Nov 1996 21:33:50 +0100 (MET) Received: from Montchapet (root@remote17.ac-dijon.fr [194.167.18.144]) by nez-perce.inria.fr (8.7.6/8.7.1) with SMTP id VAA01738 for ; Wed, 13 Nov 1996 21:33:47 +0100 (MET) Received: from Montchapet (quercia@localhost [127.0.0.1]) by Montchapet (8.6.12/8.6.9) with SMTP id WAA05581 for ; Wed, 13 Nov 1996 22:33:06 GMT Message-ID: <328A4CA0.D18858A@l-carnot1.ac-dijon.fr> Date: Wed, 13 Nov 1996 22:33:04 +0000 From: Quercia Organization: Lycee Carnot X-Mailer: Mozilla 3.0 (X11; I; Linux 2.0.0 i486) MIME-Version: 1.0 To: caml-list Subject: match values Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: weis If you can't read french, please do skip the 51 following lines. En francais : Le code Caml suivant ne fonctionne pas comme on pourrait le vouloir : let f(x,y,z) = match x with | y -> ... | z -> ... | _ -> ... ;; le compilateur signale que les cas 2 et 3 sont inutiles car le "y" du match est pris comme un identificateur nouveau et non comme le deuxieme parametre de "f". La solution est d'ecrire : let f(x,y,z) = if x = y then ... else if x = z then ... else ... ;; ou aussi : let f(x,y,z) = match 0 with | _ when x=y -> ... | _ when x=z -> ... | _ -> ... ;; mais ces deux formes ne me plaisent pas ! Peut-on envisager ? 1. de modifier la syntaxe de "match" de sorte que les identificateurs soient evalues s'ils ne sont pas precedes de "as" comme dans : match x with | y -> ... (* comparaison des valeurs x et y *) | _ as t -> ... (* definition de l'identificateur t *) 1'. sans pour autant modifier les autres formes de filtrage comme : let (u,v) = ... in ... (* definition des identificateurs u et v *) let f(u,v) = ... (* idem *) Il est probable que 1 et 1' sont inconciliables ? 2. d'introduire une nouvelle forme de filtrage "matchval" qui evaluerait les motifs avant de proceder a la comparaison, en conservant la possibilite de definir un nouvel identificateur par "_ as " ? ============================================================================== In english : The following Caml code does not work as one would expect : let f(x,y,z) = match x with | y -> ... | z -> ... | _ -> ... ;; the compiler warns that cases #2 & #3 are useless because "y" in the match construct is interpreted as a new identifier and not as the second parameter of "f". The solution is to write : let f(x,y,z) = if x = y then ... else if x = z then ... else ... ;; or : let f(x,y,z) = match 0 with | _ when x=y -> ... | _ when x=z -> ... | _ -> ... ;; but I don't like these constructs ! May I dream about ? 1. modify "match" syntax so that identifiers are evaluated unless they are precededed by "as" as in : match x with | y -> ... (* comparison of the values of x and y *) | _ as t -> ... (* definition of identifier t *) 1'. without modifying other patern-matching forms as : let (u,v) = ... in ... (* definition of identifiers u and v *) let f(u,v) = ... (* idem *) I think that 1 and 1' are incompatible ? 2. introduce a new form of pattern-matching "matchval" which would evaluate the patterns before comparison, preserving the possibility to define a new identifier with a "_ as " construct ? -- Michel Quercia Lycee Carnot 16 bd Thiers 21000 Dijon e-mail = querciam@l-carnot1.ac-dijon.fr