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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] ANN: pattern guards
On Fri, 2007-06-29 at 15:19 +0100, Jeremy Yallop wrote:
> I'm pleased to announce the initial release of `patterns', an OCaml
> extension providing general-purposes additions to pattern matching.

I want to do this:

	match x with
	| Y x with a=x and b=x
	| X (y,z) with a=y and b=z
	-> f a b

This won't work at the moment for two reasons:

* I assume the precedence of 'with' is the same as 'when',
  which is not convenient

* the variables in the basic patterns don't agree

The whole point of the above is to switch all the branches
to normalised variables. At the moment I have to write:

	match x with
	| Y x -> f x x
	| X (y,z) -> f y z

This is very bad, because either I duplicate lots of code,
or I actually define a subroutine f .. the problem with that
is that in a large match, the only place to put it is before
the top of the match .. a long way from where it is required.

The need for the above occurs in term rewriting systems
for which there are abbreviations or redundant encodings.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: