English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] ocaml and named constants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-05-29 (17:18)
From: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] ocaml and named constants
Andreas Rossberg wrote:

> >         Is there any semantic reason why
> > one cannot use variables, or even expressions? Apart from
> > the obvious syntactic problem.
> If you allow arbitrary (dynamically determined) values to be matched
> against, then pattern matching has unbound cost.

> OTOH, with the current
> form, the cost of pattern matching is always linear in the syntactic
> size of the match. 

	Unless you use a 'when' construct .. which already
provides what I was asking for. The case when this is most
annoying is for 'manifest constants':

	let c1 = 1
	and c2 = 2
	in match expr with
	| x when x = c1 -> ..
	| x when x = c2 -> ..

where the 'match' construction is still arguably cleaner than
an if/then/else chain

	let x = expr in
	if x = c1 then ..
	else if x = c2 then ..

especially if you're actually matching as well:

	match expr with
	| (x,y) when x = c1 -> ...

John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr