Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 (12:12)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: [Caml-list] ocaml and named constants
John Max Skaller wrote:
> > One motivation for this is to be able to put named constants in
> > patterns, e.g.
> >
> >      match get_next_byte() with
> >        mpg_joint_stereo -> ...
> >      | mpg_78rpm -> ...
> >      | _ -> ...
> >
> > which cannot be done in plain ML.
>         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. It might not even
terminate in the presence of circular values. OTOH, with the current
form, the cost of pattern matching is always linear in the syntactic
size of the match. I think it is good design to have potentially costly
operations explicit.

Moreover, such matching would most likely rely on structural equality.
Although this is not a technical problem since OCaml already has
structural equality, I would at least consider it questionable to
promote its (implicit!) use through such a feature.

	- Andreas

Andreas Rossberg,

"Computer games don't affect kids.
 If Pac Man affected us as kids, we would all be running around in
 darkened rooms, munching pills, and listening to repetitive music."
To unsubscribe, mail  Archives: