Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Matías Giovannini" <matias@k-bell.com>
To: caml-list@inria.fr
Subject: [Q] Multiple patterns in O'Caml
Date: Tue, 26 Jan 1999 15:49:28 -0300	[thread overview]
Message-ID: <36AE0E34.6BF3A367@k-bell.com> (raw)

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.




             reply	other threads:[~1999-01-27 18:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-26 18:49 Matías Giovannini [this message]
1999-01-27 14:02 ` Pierre Weis

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=36AE0E34.6BF3A367@k-bell.com \
    --to=matias@k-bell.com \
    --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