Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Pattern matching fallthrough with guards
@ 2006-11-28 19:01 taras
  2006-11-28 19:53 ` [Caml-list] " Martin Jambon
  0 siblings, 1 reply; 2+ messages in thread
From: taras @ 2006-11-28 19:01 UTC (permalink / raw)
  To: caml-list

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?

Taras


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Pattern matching fallthrough with guards
  2006-11-28 19:01 Pattern matching fallthrough with guards taras
@ 2006-11-28 19:53 ` Martin Jambon
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Jambon @ 2006-11-28 19:53 UTC (permalink / raw)
  To: taras; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-11-28 19:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-28 19:01 Pattern matching fallthrough with guards taras
2006-11-28 19:53 ` [Caml-list] " Martin Jambon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox