Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Q] Multiple patterns in O'Caml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <Pierre.Weis@i...>
Subject: Re: [Q] Multiple patterns in O'Caml
> (* 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/