Last active
September 7, 2017 12:42
-
-
Save chenglou/a8078054d3e22524b30ff9e7a58a230f to your computer and use it in GitHub Desktop.
Revised syntax labelled function argument. **The only difference is between ~ and :**
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* == definition == */ | |
/* two labelled arguments, one unlabelled */ | |
let display = (~message, ~person, time) => 1; | |
/* with default value */ | |
let display = (~message="hello", ~person="Reason", time) => 1; | |
/* with type annotation */ | |
let display = (~message: string, ~person: string, time: float) => 1; | |
/* type annoation and with default */ | |
let display = (~message: string="hello", ~person: string="Reason", time: float) => 1; | |
/* == call == */ | |
/* normal */ | |
display(~message="hey", ~person="Reason", 2.0); | |
/* call with punning, aka ~message=message */ | |
display(~message, ~person, 2.0); | |
/* == type definition == */ | |
/* normal */ | |
type d = (~message: string, ~person: string, float) => int; | |
/* with default */ | |
type d = (~message: string=?, ~person: string=?, float) => int; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* == definition == */ | |
/* two labelled arguments, one unlabelled */ | |
let display = (:message, :person, time) => 1; | |
/* with default value */ | |
let display = (:message="hello", :person="Reason", time) => 1; | |
/* with type annotation */ | |
let display = (:message: string, :person: string, time: float) => 1; | |
/* type annoation and with default */ | |
let display = (:message: string="hello", :person: string="Reason", time: float) => 1; | |
/* == call == */ | |
/* normal */ | |
display(:message="hey", :person="Reason", 2.0); | |
/* call with punning, aka :message=message */ | |
display(:message, :person, 2.0); | |
/* == type definition == */ | |
/* normal */ | |
type d = (:message: string, :person: string, float) => int; | |
/* with default */ | |
type d = (:message: string=?, :person: string=?, float) => int; |
I prefer ~
over :
only because :
is already meaningful for types - wouldn't want to overload that meaning.
I vote for
/* two labelled arguments, one unlabelled */
let display = (@message, @person, time) => 1;
/* with default value */
let display = (@message="hello", @person="Reason", time) => 1;
/* with type annotation */
let display = (@message: string, @person: string, time: float) => 1;
/* type annoation and with default */
let display = (@message: string="hello", @person: string="Reason", time: float) => 1;
/* == call == */
/* normal */
display(@message="hey", @person="Reason", 2.0);
/* call with punning, aka @message=message */
display(@message, @person, 2.0);
/* == type definition == */
/* normal */
type d = (@message: string, @person: string, float) => int;
/* with default */
type d = (@message: string=?, @person: string=?, float) => int;
Tilde please. Like others have said, I think overloading the meaning of symbols is not a wise thing to do. The tilde is unique and while it might seem weird the first 5 times a newcomer looks at it, it is easy to digest. Thowing :
everywhere is awfully confusing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Agree with @fstiffo : Why create more verbose syntax ?
About the initial question I prefer the first one (~) like in OCaml
The second (:) may be confusing about the meaning of ':' symbol in ReasonML