Version française
Home     About     Download     Resources     Contact us    
Browse thread
Pattern matching fallthrough with guards
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin1977@l...>
Subject: Re: [Caml-list] Pattern matching fallthrough with guards
On Tue, 28 Nov 2006, taras wrote:

> Hi,
> I noticed that one can coalesce multiple patterns like
>
> function Some _
>      | None -> 0
>
> However when I add guards to this hypothetical example, I get a syntax error
>
> function Some _ when 1 = 2
>     |  None -> 0
>
> I'm wondering if this inconsistency is considered to be a bug or not?

It's not a bug.
The "when" guard must come just before the arrow.
But the vertical bar may be more powerful than what you expect. You can do
this:

function Some (0|1) | None -> ...
       | ...

Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr