Re: [Q] Multiple patterns in O'Caml

From: Pierre Weis (Pierre.Weis@inria.fr)
Date: Wed Jan 27 1999 - 15:02:49 MET


From: Pierre Weis <Pierre.Weis@inria.fr>
Message-Id: <199901271402.PAA15684@pauillac.inria.fr>
Subject: Re: [Q] Multiple patterns in O'Caml
To: matias@k-bell.com
Date: Wed, 27 Jan 1999 15:02:49 +0100 (MET)
In-Reply-To: <36AE0E34.6BF3A367@k-bell.com> from "=?iso-8859-1?Q?Mat=EDas?= Giovannini" at Jan 26, 99 03:49:28 pm

> (* 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.

There is no spurious construction of tuples nor subsequent destuction
when matching an immediate tuple: this is optimised by the compiler of
Objective Caml. This way you can consider writing

match x, y, z with
| 1, 2, 3 -> ...
...

as a syntactic notation for ``parallel matching'', or matching of more
than one value at a time.

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:18 MET