Browse thread
[Caml-list] ocaml and named constants
-
David Fox
-
Xavier Leroy
-
John Max Skaller
-
Andreas Rossberg
- John Max Skaller
-
Andreas Rossberg
-
John Max Skaller
-
Xavier Leroy
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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