Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Luc Maranget <luc.maranget@inria.fr>
To: skaller <skaller@ozemail.com.au>
Cc: Pierre Weis <pierre.weis@inria.fr>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Question
Date: Thu, 11 Dec 2003 10:52:45 +0100	[thread overview]
Message-ID: <20031211105245.A2501@beaune.inria.fr> (raw)
In-Reply-To: <1071071631.4023.16.camel@pelican>; from skaller@ozemail.com.au on Thu, Dec 11, 2003 at 02:53:51AM +1100


> > 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
round.

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 ?


Cheers,
-- 
Luc Maranget

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2003-12-11  9:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-01 15:41 sebastien FURIC
2003-12-01 17:48 ` Remi Vanicat
2003-12-01 18:04   ` sebastien FURIC
2003-12-03 14:02 ` Damien Doligez
2003-12-10 10:27 ` Pierre Weis
2003-12-10 15:53   ` skaller
2003-12-11  9:52     ` Luc Maranget [this message]
2003-12-11 14:20       ` skaller
2003-12-11 16:56         ` Luc Maranget
2005-05-23  6:54 Question  dsingh01
2005-05-23  7:40 ` [Caml-list] Question Remi Vanicat
2005-05-23 12:21 ` Jacques Carette
2005-06-08 10:06 question  dsingh01
2005-06-08 15:13 ` [Caml-list] question Damien Bobillot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031211105245.A2501@beaune.inria.fr \
    --to=luc.maranget@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=pierre.weis@inria.fr \
    --cc=skaller@ozemail.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox