* [Caml-list] strange compiler's tolerance
@ 2013-10-24 13:47 Matej Kosik
2013-10-24 14:02 ` Pippijn van Steenhoven
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Matej Kosik @ 2013-10-24 13:47 UTC (permalink / raw)
To: caml-list
Hi,
Today I noticed a strange compiler's tolerance.
The compiler will not protest here:
type foo = Bar | Baz
;;
match Bar with
| Bar _ -> ()
| Baz -> ()
Why doesn't the compiler protest that I used wildcard after "Bar" constructor?
(It does protest if I put any other pattern except for the wildcard).
This slightly breaks the logic. Doesn't it?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] strange compiler's tolerance
2013-10-24 13:47 [Caml-list] strange compiler's tolerance Matej Kosik
@ 2013-10-24 14:02 ` Pippijn van Steenhoven
2013-10-24 14:05 ` Gabriel Scherer
2013-10-24 14:35 ` Virgile Prevosto
2 siblings, 0 replies; 4+ messages in thread
From: Pippijn van Steenhoven @ 2013-10-24 14:02 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 133 bytes --]
Hi,
OCaml as of 4.00.1 does complain about this with a warning. Allowing it
is mostly useful (and used) in generated code.
Pippijn
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] strange compiler's tolerance
2013-10-24 13:47 [Caml-list] strange compiler's tolerance Matej Kosik
2013-10-24 14:02 ` Pippijn van Steenhoven
@ 2013-10-24 14:05 ` Gabriel Scherer
2013-10-24 14:35 ` Virgile Prevosto
2 siblings, 0 replies; 4+ messages in thread
From: Gabriel Scherer @ 2013-10-24 14:05 UTC (permalink / raw)
To: Matej Kosik; +Cc: caml users
[-- Attachment #1: Type: text/plain, Size: 1324 bytes --]
The pattern _ has been extended to accept any number of arguments. If you
think of it
type foo = Foo of int * bool
let f (Foo _) = ()
is already quite strange (replacing _ by a variable here doesn't work), but
extremely convenient (you don't want to have to remember the constructor's
arity just to ignore it). It was extended to 0-ary constructors for
consistency, but you can disable this allowance by marking warning 28
(ocamlc -warn-help) as an error.
On Thu, Oct 24, 2013 at 3:47 PM, Matej Kosik <
5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote:
> Hi,
>
> Today I noticed a strange compiler's tolerance.
> The compiler will not protest here:
>
> type foo = Bar | Baz
>
> ;;
>
> match Bar with
> | Bar _ -> ()
> | Baz -> ()
>
> Why doesn't the compiler protest that I used wildcard after "Bar"
> constructor?
> (It does protest if I put any other pattern except for the wildcard).
>
> This slightly breaks the logic. Doesn't it?
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/**arc/caml-list<https://sympa.inria.fr/sympa/arc/caml-list>
> Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners<http://groups.yahoo.com/group/ocaml_beginners>
> Bug reports: http://caml.inria.fr/bin/caml-**bugs<http://caml.inria.fr/bin/caml-bugs>
>
[-- Attachment #2: Type: text/html, Size: 2032 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] strange compiler's tolerance
2013-10-24 13:47 [Caml-list] strange compiler's tolerance Matej Kosik
2013-10-24 14:02 ` Pippijn van Steenhoven
2013-10-24 14:05 ` Gabriel Scherer
@ 2013-10-24 14:35 ` Virgile Prevosto
2 siblings, 0 replies; 4+ messages in thread
From: Virgile Prevosto @ 2013-10-24 14:35 UTC (permalink / raw)
To: OCAML
Hello,
2013/10/24 Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>:
> Hi,
>
> Today I noticed a strange compiler's tolerance.
> The compiler will not protest here:
>
> type foo = Bar | Baz
>
> ;;
>
> match Bar with
> | Bar _ -> ()
> | Baz -> ()
>
It's not a bug, it's a "dubious feature". See
http://caml.inria.fr/mantis/view.php?id=5502 for more information. If
like me you indeed find that's it's more dubious than a feature,
warning 28
"Wildcard pattern given as argument to a constant constructor" is your
friend and is set by default.
Best regards,
--
E tutto per oggi, a la prossima volta
Virgile
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-10-24 14:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-24 13:47 [Caml-list] strange compiler's tolerance Matej Kosik
2013-10-24 14:02 ` Pippijn van Steenhoven
2013-10-24 14:05 ` Gabriel Scherer
2013-10-24 14:35 ` Virgile Prevosto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox