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] Question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-12-11 (09:52)
From: Luc Maranget <luc.maranget@i...>
Subject: Re: [Caml-list] Question

> > The when construct introduces a guard to a pattern matching
> > clause. This means that a when construct is global to the entire
> > pattern of the clause it appears in; it means in particular that no
> > when construct can be nested into a pattern and the question of its
> > distributivity wrt any other construct is pointless.
> > 
> > >  Is there a good reason for this?
> > 
> > Yes: simplicity, complexity invariants preservation for runtime
> > pattern analysis decisions even in the presence of when clauses,
> > easier understanding of the compiler warnings, simplicity and
> > well-definedness semantics (in particular the desired invariance wrt
> > the order of evaluation).
> Whoa! Can you say that slower? Felix allows nested when clauses
> in patterns (however it doesn't allow alternatives yet). 
> The current implementation is unoptimised, 
> I just evaluate the match of each pattern in turn until one matches.
> One small difference .. the argument of a when clause is
> an expression .. and felix expressions are purely functional
> so there is no issue of order of evaluation changing anything.
> So, what have I lost?

In some sense order of evaluation may not be an issue
(at worst it can be left unspecified!).
That said.

  When clauses inside patterns would for sure much complicate optimized
compilation and maybe diagnostics. So basically you loose optimised
compilation and simple diagnostics.

  Moreover at the moment the AST types for patterns and expression are
not mutually recursive. Expressions depend on patterns but not the other way

As far as I know, The compiler take advantage of this in many places,
with code that more or less looks as follows

let rec treat_pat = blabala

let rec treat_expr = blabla ... treat_pat ...

Making patterns and expressions mutually dependant, would perhaps,
break some untold assumption, hidden invariant etc.

To conclude adopting the Felix way in Ocaml is by no mean a trivial
change and benefits are unclear, how many programs do realy use this
feature ?

Luc Maranget

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: