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

labeled argument in module #5488

Closed
vicuna opened this issue Jan 20, 2012 · 5 comments
Closed

labeled argument in module #5488

vicuna opened this issue Jan 20, 2012 · 5 comments

Comments

@vicuna
Copy link

vicuna commented Jan 20, 2012

Original bug ID: 5488
Reporter: @lefessan
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2017-03-16T00:39:23Z)
Resolution: won't fix
Priority: normal
Severity: feature
Version: 3.13.0+dev
Category: language features
Tags: patch
Monitored by: @gasche @hcarty

Bug description

Suppose you have a function:

module List : sig
...
val sort : 'a t -> compare:('a -> 'a -> int) -> 'a t
end

Further, suppose you have:

module Int : sig
...
val compare : t -> t -> int
end

Then you could write:

List.sort ints ~compare:Int.compare

Or, you could write:

Int.(List.compare ints ~compare)
It would be nicer to instead just write:

List.sort ints ~Int.compare

To be precise, when passing a labeled argument without using :, module prefixes would be allowed. Only the name of the value (excluding the module path) would be required to match the label name in the function signature.

I provide a patch for this in attachment.

File attachments

@vicuna
Copy link
Author

vicuna commented Jan 20, 2012

Comment author: @alainfrisch

This is nice. I've a little concern: if this is accepted, users might (with reason) ask the same for record fields with punning. But the syntax { A.x } already has a different meaning (namely { A.x = x }, and not { x = A.x }).

@vicuna
Copy link
Author

vicuna commented Jan 21, 2012

Comment author: @garrigue

Originally the intent of the ~ident notation is to make easier using labeled arguments in recursive functions, or in function calls where an argument has the same meaning.
I don't think that extending this to values inside modules is very reasonable.
Moreover, as Alain points out, this would not be coherent with the punning for records.

So I vote not to do this: you just have to type a few more characters...

@vicuna
Copy link
Author

vicuna commented Jan 22, 2012

Comment author: @lefessan

I understand Alain's concern, but this is a problem with record label qualification, that should not have been done like that. "A.{ x
; y; z }" would have been a much better syntax (and much easier to understand, you qualify the record, not the content).

It is a pity that such a mistake would now prevent the introduction of an unambiguous syntax (with labels, there is no risk of ambiguity, about what is qualified by the module).

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @mshinwell

Can we come to a final decision on this?

@vicuna
Copy link
Author

vicuna commented Mar 16, 2017

Comment author: @garrigue

While I can understand why you would wish to write more compact code, you already describe how to this with a local open. From the point of view of readability, I think this is clearer not to introduce yet another rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants