Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Quercia <querciam@l-carnot1.ac-dijon.fr>
To: caml-list <caml-list@inria.fr>
Subject: match values
Date: Wed, 13 Nov 1996 22:33:04 +0000	[thread overview]
Message-ID: <328A4CA0.D18858A@l-carnot1.ac-dijon.fr> (raw)

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 <ident>" ?

==============================================================================

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 <ident>" construct ?

-- 
Michel Quercia
Lycee Carnot  16 bd Thiers  21000 Dijon
e-mail = querciam@l-carnot1.ac-dijon.fr





             reply	other threads:[~1996-11-14  9:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-13 22:33 Quercia [this message]
1996-11-14 15:03 ` Pierre Weis
1996-11-15  6:59 QUERCIA Michel (T) Math

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=328A4CA0.D18858A@l-carnot1.ac-dijon.fr \
    --to=querciam@l-carnot1.ac-dijon.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox