Skip to content
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

Closed
vicuna opened this Issue Aug 9, 2018 · 7 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link
Collaborator

vicuna commented Aug 9, 2018

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 = ()

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 9, 2018

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.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 9, 2018

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 = ()
let g = f ~b:()

is equivalent to

let g ?a = ()

which triggers warning 16. As I understand it, argument ?a in f cannot be erased.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 9, 2018

Comment author: @nojb

Re-opening as I misunderstood the issue.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 9, 2018

Comment author: @nojb

#1983

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 9, 2018

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.

@vicuna vicuna closed this Aug 9, 2018

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 9, 2018

Comment author: jtsang

Thanks for clearing it up.

Can we have a doc change that clarifies this?

Something like

Note 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.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Aug 9, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.