caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Carette <carette@mcmaster.ca>
To: skaller <skaller@users.sourceforge.net>
Cc: OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Patterns that evaluate
Date: Thu, 15 Feb 2007 08:41:02 -0500	[thread overview]
Message-ID: <45D462EE.5040100@mcmaster.ca> (raw)
In-Reply-To: <1171511618.13529.49.camel@rosella.wigram>

skaller wrote:
> It is a common wish, but has many problems IMHO.
> First, it isn't very general. 
Fallacious argument: OCaml has records, so there is no need for tuples 
which are less general.  Yet it has them. 
The point is to balance generality with convenience.  That is why 
redundancy in a language may be a pain for the compiler writers, but can 
make a big difference to the users.

Note that I was not suggesting, ever, that OCaml's current 
pattern-matching be 'broken' by blindly adding 'active' views.  A 
different syntax would seem to make sense. 

> [...] and more generally
> patterns from expressions, would be extremely fragile:
>
> 	let h = 1 in 
> 	match x with
> 	| h :: t -> ...
>
> The meaning of this matching appears to be to match
> a list starting with 1, binding t to the tail .. but
> it all depends on whether t is a symbol in the context
> of this fragment. The meaning would change if t were
> not in the context and a programmer introduced it:
>   
Sure.  But that is the normal semantics of the rest of OCaml you're 
complaining about here!  Yes, having a pattern-matching mechanism which 
is context dependent (like the rest of OCaml) instead of always working 
in an empty environment is different, that is expected.

Personally, I find that I don't write programs with a lot of variable 
shadowing, I tend to use new names in matches.  And no globals.  I 
consider them both to be bad style ;-)


> Thirdly it leaves open the issue of non-linear patterns:
> 	| x , x -> ...
>   
If x had a value, this would not be a problem at all.  It is only a 
problem in the 'binding' case.

> I also often match nasty patterns in many places and really
> wish I could name them:
>
> 	pattern p(x) = C x
> 	match e with | p(x) -> ...
>
> doesn't provide active patterns, but it would be quite useful.
>   
Agreed, that would be nice.

Regarding Jay-style matching: I was _expecting_ some kind of active 
patterns to work, I _want_ Jay style patterns.  Very different!

Jacques


  reply	other threads:[~2007-02-15 13:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-13 22:04 Jacques Carette
2007-02-13 22:07 ` [Caml-list] " Jon Harrop
2007-02-14  0:10   ` Jacques Carette
2007-02-14 18:20   ` Edgar Friendly
2007-02-14 18:55     ` Gerd Stolpmann
2007-02-14 19:10       ` Denis Bueno
2007-02-14 19:11       ` Jacques Carette
2007-02-14 19:25         ` Gerd Stolpmann
2007-02-14 20:30           ` Edgar Friendly
2007-02-14 21:05       ` Jon Harrop
2007-02-14 21:33         ` Jacques Carette
2007-02-14 22:34   ` Martin Jambon
2007-02-15  0:26     ` Jacques Garrigue
2007-02-15  3:57       ` Jon Harrop
2007-02-15 22:43         ` Don Syme
2007-02-14 20:29 ` Nathaniel Gray
2007-02-14 21:10   ` Jacques Carette
2007-02-15  3:53     ` skaller
2007-02-15 13:41       ` Jacques Carette [this message]
2007-02-15 14:10         ` skaller
2007-02-15 20:43     ` Nathaniel Gray
2007-03-07 11:15       ` Oliver Bandel

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=45D462EE.5040100@mcmaster.ca \
    --to=carette@mcmaster.ca \
    --cc=caml-list@inria.fr \
    --cc=skaller@users.sourceforge.net \
    /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;
as well as URLs for NNTP newsgroup(s).