New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning 16 inconsistent #7836
Comments
Comment author: @nojb This behaviour is as expected. Briefly, functions with optional arguments must take at least one non-optional argument so that the compiler can decide which arguments have been omitted, and order matters. See section 4.1.1 of the manual https://caml.inria.fr/pub/docs/manual-ocaml/lablexamples.html for more information. |
Comment author: jtsang The criterion for deciding whether an optional argument has been omitted is the non-labeled application of an argument appearing after this optional argument in the function type. Note that if that argument is labeled, you will only be able to eliminate optional arguments through the special case for total applications. The problem is (and I got hit by it): let f ?a ~b = () is equivalent to let g ?a = () which triggers warning 16. As I understand it, argument ?a in f cannot be erased. |
Comment author: @nojb Re-opening as I misunderstood the issue. |
Comment author: @nojb So, after all, this is expected behaviour. You can erase ?a by passing all other arguments (in this case, just ~b) without the labels. See the discussion in the PR for more. |
Comment author: jtsang Thanks for clearing it up. Can we have a doc change that clarifies this? Something likeNote that if that argument is labeled, you will only be able to eliminate optional arguments by totally applying the function, omitting all optional arguments and omitting all labels for all arguments.I find it unexpected that in let f a ~b ?c ~d ~e = () the only erasing call that succeeds is exactly f () () () () with zero labels. |
Comment author: @nojb I agree the doc is a bit unclear on this point. Would you like to open a PR with your doc suggestion? Otherwise, I could do it. |
Original bug ID: 7836
Reporter: jtsang
Assigned to: @nojb
Status: resolved (set by @nojb on 2018-08-09T20:46:50Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 4.06.1
Category: typing
Bug description
The following triggers warning 16 (optional argument cannot be erased):
let f ?a = ()
let f ~b ?a = ()
The following does not:
let f ?a ~b = ()
The text was updated successfully, but these errors were encountered: