caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Pattern matching missing (or brain damage?)
@ 2002-07-18 22:22 Alessandro Baretta
  2002-07-18 22:36 ` Michael Vanier
  2002-07-19  0:08 ` William Lovas
  0 siblings, 2 replies; 5+ messages in thread
From: Alessandro Baretta @ 2002-07-18 22:22 UTC (permalink / raw)
  To: Ocaml

I believe I remember a pattern matching construct where an 
expression could be associated with multiple patterns.

match <expr> with
| A(_) | B(_) | C(_) -> foo
| C(_) | D(_) | E(_) -> bar

Neither does the compiler accept such code, nor does the 
manual mention such construct. Has it been removed from the 
language or am I suffering severe brain damage from too much 
O'Caml coding?

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Pattern matching missing (or brain damage?)
  2002-07-18 22:22 [Caml-list] Pattern matching missing (or brain damage?) Alessandro Baretta
@ 2002-07-18 22:36 ` Michael Vanier
  2002-07-20 15:28   ` Oleg
  2002-07-19  0:08 ` William Lovas
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Vanier @ 2002-07-18 22:36 UTC (permalink / raw)
  To: alex; +Cc: caml-list



# type ex = A of int | B of int | C of int | D of int | E of int;;
type ex = A of int | B of int | C of int | D of int | E of int
# let a = A 1000;;
val a : ex = A 1000
# match a with
     A(_) | B(_) | C(_) -> "foo"
  |  C(_) | D(_) | E(_) -> "bar";;
- : string = "foo"

You put in an extra | before the A(_).

Mike


> Date: Fri, 19 Jul 2002 00:22:44 +0200
> From: Alessandro Baretta <alex@baretta.com>
> 
> I believe I remember a pattern matching construct where an 
> expression could be associated with multiple patterns.
> 
> match <expr> with
> | A(_) | B(_) | C(_) -> foo
> | C(_) | D(_) | E(_) -> bar
> 
> Neither does the compiler accept such code, nor does the 
> manual mention such construct. Has it been removed from the 
> language or am I suffering severe brain damage from too much 
> O'Caml coding?
> 
> Alex
> 
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> 
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Pattern matching missing (or brain damage?)
  2002-07-18 22:22 [Caml-list] Pattern matching missing (or brain damage?) Alessandro Baretta
  2002-07-18 22:36 ` Michael Vanier
@ 2002-07-19  0:08 ` William Lovas
  2002-07-19  1:09   ` Alessandro Baretta
  1 sibling, 1 reply; 5+ messages in thread
From: William Lovas @ 2002-07-19  0:08 UTC (permalink / raw)
  To: Ocaml

On Fri, Jul 19, 2002 at 12:22:44AM +0200, Alessandro Baretta wrote:
> I believe I remember a pattern matching construct where an 
> expression could be associated with multiple patterns.
> 
> match <expr> with
> | A(_) | B(_) | C(_) -> foo
> | C(_) | D(_) | E(_) -> bar
> 
> Neither does the compiler accept such code, nor does the 
> manual mention such construct. Has it been removed from the 
> language or am I suffering severe brain damage from too much 
> O'Caml coding?

This is legal.  It's covered in the Chapter 6 of the manual, under
Patterns, sub-heading ``Or'' patterns:

    http://caml.inria.fr/ocaml/htmlman/manual014.html

You might be having trouble if your subpatterns don't bind exactly 
the same variables...

William
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Pattern matching missing (or brain damage?)
  2002-07-19  0:08 ` William Lovas
@ 2002-07-19  1:09   ` Alessandro Baretta
  0 siblings, 0 replies; 5+ messages in thread
From: Alessandro Baretta @ 2002-07-19  1:09 UTC (permalink / raw)
  To: William Lovas, Michael Vanier, Ocaml



William Lovas wrote:
> 
> This is legal.  It's covered in the Chapter 6 of the manual, under
> Patterns, sub-heading ``Or'' patterns:
> 
>     http://caml.inria.fr/ocaml/htmlman/manual014.html
> 
> You might be having trouble if your subpatterns don't bind exactly 
> the same variables...

Many thanks to both William and Michael.

No, I was not having trouble with the bindings, since I was 
only checking the variant tag. The problem is that I'm still 
writing code at 3 in the morning. But at last I got it to 
compile, yeah! Tomorrow, debugging...

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Pattern matching missing (or brain damage?)
  2002-07-18 22:36 ` Michael Vanier
@ 2002-07-20 15:28   ` Oleg
  0 siblings, 0 replies; 5+ messages in thread
From: Oleg @ 2002-07-20 15:28 UTC (permalink / raw)
  To: Michael Vanier; +Cc: caml-list

On Thursday 18 July 2002 06:36 pm, Michael Vanier wrote:
> # match a with
>      A(_) | B(_) | C(_) -> "foo"
>   |  C(_) | D(_) | E(_) -> "bar";;
> - : string = "foo"
>
> You put in an extra | before the A(_).

It's optional

Regards,
Oleg
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2002-07-20 15:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-18 22:22 [Caml-list] Pattern matching missing (or brain damage?) Alessandro Baretta
2002-07-18 22:36 ` Michael Vanier
2002-07-20 15:28   ` Oleg
2002-07-19  0:08 ` William Lovas
2002-07-19  1:09   ` Alessandro Baretta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).