Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007836OCamltypingpublic2018-08-09 20:432018-08-09 23:18
Assigned Tonojebar 
StatusresolvedResolutionno change required 
PlatformOSOS Version
Product Version4.06.1 
Target VersionFixed in Version 
Summary0007836: Warning 16 inconsistent
DescriptionThe following triggers warning 16 (optional argument cannot be erased):

let f ?a = ()
let f ~b ?a = ()

The following does not:

let f ?a ~b = ()
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
nojebar (developer)
2018-08-09 20:57

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 [^] for more information.
jtsang (reporter)
2018-08-09 21:04

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.
nojebar (developer)
2018-08-09 21:16

Re-opening as I misunderstood the issue.
nojebar (developer)
2018-08-09 22:22 [^]
nojebar (developer)
2018-08-09 22:46

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.
jtsang (reporter)
2018-08-09 23:10

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.
nojebar (developer)
2018-08-09 23:18

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.

- Issue History
Date Modified Username Field Change
2018-08-09 20:43 jtsang New Issue
2018-08-09 20:57 nojebar Note Added: 0019293
2018-08-09 20:57 nojebar Status new => resolved
2018-08-09 20:57 nojebar Resolution open => no change required
2018-08-09 20:57 nojebar Assigned To => nojebar
2018-08-09 21:04 jtsang Note Added: 0019294
2018-08-09 21:16 nojebar Note Added: 0019295
2018-08-09 21:16 nojebar Status resolved => new
2018-08-09 22:22 nojebar Note Added: 0019296
2018-08-09 22:23 nojebar Status new => assigned
2018-08-09 22:46 nojebar Note Added: 0019297
2018-08-09 22:46 nojebar Status assigned => resolved
2018-08-09 23:10 jtsang Note Added: 0019298
2018-08-09 23:18 nojebar Note Added: 0019299

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker