Version française
Home     About     Download     Resources     Contact us    
Browse thread
proposed extenion to patterns
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tom <tom.primozic@g...>
Subject: Re: [Caml-list] proposed extenion to patterns
On 09/03/07, skaller <skaller@users.sourceforge.net> wrote:
>
> Pattern matches in Ocaml now allow alternatives within
> a branch subject to a restriction that all alternatives
> supply the same set of pattern variables (and of the same type).
>
> This is useful but still quite restrictive, for example:
>
> | A (i,j) | B i with j = 1 -> i + j


 I think this is a good idea.

This form looks more general:
>
> | in A (h,k) let i = h and k = k
> | in B s let i = s + 1 let k = i
>


But I find this too complicated (for a programmer to memorize the syntax,
write it and someone else read it). You could simply say:

  | A (h as i, k as k)
  | B s with i = s + 1 and k = i

I know that this would introduce some problems (not equal variable in both
branches, but this could easily be solved (the compiler only complaining
when a non-common variable is actually used (in this example, h and s)).

- Tom