Version française
Home     About     Download     Resources     Contact us    
Browse thread
Patterns that evaluate
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Carette <carette@m...>
Subject: Re: [Caml-list] Patterns that evaluate
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