From: David Allsopp <dra-news@metastack.com>
To: William <r.3@libertysurf.fr>, "caml-list@inria.fr" <caml-list@inria.fr>
Subject: RE: [Caml-list] ocaml 4.03 and warning 52 : argument of this constructor should not be matched against a constant pattern
Date: Wed, 27 Apr 2016 09:28:41 +0000 [thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D9F044D3B7@Remus.metastack.local> (raw)
In-Reply-To: <572084CC.1080408@libertysurf.fr>
William wrote:
> Hello,
>
> with ocaml 4.03, I came with many warnings such as this one :
>
> let lst = [] in
> try
> let fst = List.hd lst in
> Printf.printf "fst:%s\n" fst
> with
> | Failure "hd" -> Printf.printf "empty list\n";;
>
> Characters 123-127:
> | Failure "hd" -> Printf.printf "empty list\n";;
> ^^^^
> Warning 52: the argument of this constructor should not be matched against
> a constant pattern; the actual value of the argument could change in the
> future.
>
>
>
> It occurs typically for Failure "hd", Failure "tl", Failure
> "float_of_string", Failure "int_of_string", Failure "lexing: empty token",
> Invalid_argument "Filename.chop_extension", ...
>
> How are we supposed to handle this nicely with the standard library ? Is
> there a better approach to catch those exceptions ?
In most (hopefully all) of those instances, what you're matching is Failure - i.e. the function in question only raises it in one instance, so I think the idea now is that you should match against [Failure _] rather than including the string in the match. failwith is used in too many places in the Standard Library, but that of course can't now be changed (cf. ExtList.List.Empty_list and others)
That said, Failure "lexing: empty token" is an odd one, because I certainly have lexers which have to emulate that...
David
next prev parent reply other threads:[~2016-04-27 9:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-27 9:22 William
2016-04-27 9:28 ` David Allsopp [this message]
2016-04-27 9:36 ` Daniel Bünzli
2016-04-27 9:43 ` Jacques-Henri Jourdan
2016-04-27 9:51 ` Roberto Di Cosmo
2016-04-27 10:00 ` Daniel Bünzli
2016-04-27 10:04 ` Jacques-Henri Jourdan
2016-04-28 7:25 ` Goswin von Brederlow
2016-04-27 11:01 ` Gabriel Scherer
2016-04-27 17:17 ` Adrien Nader
2016-04-27 18:20 ` Gabriel Scherer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E51C5B015DBD1348A1D85763337FB6D9F044D3B7@Remus.metastack.local \
--to=dra-news@metastack.com \
--cc=caml-list@inria.fr \
--cc=r.3@libertysurf.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox