* Strange matching-problem... ?!
@ 2005-01-27 12:20 Oliver Bandel
2005-01-27 12:31 ` [Caml-list] " Ville-Pertti Keinonen
2005-01-27 12:33 ` Frederic van der Plancke
0 siblings, 2 replies; 3+ messages in thread
From: Oliver Bandel @ 2005-01-27 12:20 UTC (permalink / raw)
To: caml-list
Hello,
any idea about this?!
# type foobar = Foo | Bar;;
type foobar = Foo | Bar
# match Foo with
Foo -> "foo"
| Bar -> "bar";;
- : string = "foo"
# match Foo with
_Foo -> "foo"
|Bar -> "bar";;
Warning: this match case is unused.
- : string = "foo"
# match Foo with
_ Foo -> "foo"
| Bar -> "bar";;
Syntax error
# match Foo with
_Bar -> "bar"
| Foo -> "foo";;
Warning: this match case is unused.
- : string = "bar"
# type foobar2 = _Foo | Bar;;
Syntax error
#
Why is the second match working without any error message?
Did I ovelooked something?
I found that behaviour, after I tried to
use Sumtypes starting with an "_" in the name.
Using such things like _Foo instead of Foo
does not yield any error message, but when defining
the type with _Foo then ocaml complains about my
wrong syntax.
What's going on here and why?
TIA,
Oliver
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Strange matching-problem... ?!
2005-01-27 12:20 Strange matching-problem... ?! Oliver Bandel
@ 2005-01-27 12:31 ` Ville-Pertti Keinonen
2005-01-27 12:33 ` Frederic van der Plancke
1 sibling, 0 replies; 3+ messages in thread
From: Ville-Pertti Keinonen @ 2005-01-27 12:31 UTC (permalink / raw)
To: Oliver Bandel; +Cc: caml-list
On Thu, 2005-01-27 at 13:20 +0100, Oliver Bandel wrote:
> # match Foo with
> _Foo -> "foo"
> |Bar -> "bar";;
> Warning: this match case is unused.
> - : string = "foo"
Here, you're matching the value Foo against a catch-all pattern with a
variable called _Foo. This is equivalent to writing:
match <anything> with
x -> "foo"
| <anything> -> "bar"
The first case matches any value.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Strange matching-problem... ?!
2005-01-27 12:20 Strange matching-problem... ?! Oliver Bandel
2005-01-27 12:31 ` [Caml-list] " Ville-Pertti Keinonen
@ 2005-01-27 12:33 ` Frederic van der Plancke
1 sibling, 0 replies; 3+ messages in thread
From: Frederic van der Plancke @ 2005-01-27 12:33 UTC (permalink / raw)
To: caml-list
Oliver Bandel wrote:
> # match Foo with
> _Bar -> "bar"
> | Foo -> "foo";;
> Warning: this match case is unused.
> - : string = "bar"
>
> # type foobar2 = _Foo | Bar;;
> Syntax error
> #
>
> Why is the second match working without any error message?
> Did I ovelooked something?
>
> I found that behaviour, after I tried to
> use Sumtypes starting with an "_" in the name.
Doesn't _ work as a lowercase letter ?
Then _Foo and _Bar are not valid sum type tags, but they are valid
variable names hence
match Foo with
_Bar -> "bar"
| Foo -> "foo";;
works exactly like
match Foo with
x -> "bar"
| Foo -> "foo";;
would.
Frédéric
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-01-27 12:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-27 12:20 Strange matching-problem... ?! Oliver Bandel
2005-01-27 12:31 ` [Caml-list] " Ville-Pertti Keinonen
2005-01-27 12:33 ` Frederic van der Plancke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox