Skip to content

Instantly share code, notes, and snippets.

@bsansouci
Created April 3, 2017 19:08
Show Gist options
  • Save bsansouci/614940d0edf240f27067bce6d0d06d36 to your computer and use it in GitHub Desktop.
Save bsansouci/614940d0edf240f27067bce6d0d06d36 to your computer and use it in GitHub Desktop.
/* The only whitespace sensitivity here is between the first colon and the named argument
let a c :b => c
VS
let a c : b => c
The former is a function that takes 2 arguments where the 2nd one is a named argument, and it returns `c` of open type.
The latter one is a function that takes one argument and that returns `c` of type `b`
*/
let a = 10;
let b = 20;
/*A*/
let named(:a, :b) => a + b;
type named = :a:int => :b:int => int;
/*B*/
let namedAlias(:a aa, :b bb) => aa + bb;
type namedAlias = :a:int => :b:int => int;
/*C*/
let namedAnnot(:a:int, :b):int => 20;
/*D*/
let namedAliasAnnot(:a aa:int, :b bb):int => 20;
/*E */
let myOptional(:a=?, :b=?, ()) => 10;
type named = :a:int? => :b:int? => unit => int;
/*F*/
let optionalAlias(:a aa = ?, :b bb = ?, ()) => 10;
/*G - Ben: the type is technically an int? (ie optional int) */
let optionalAnnot(:a = ? : int?, :b=? : int?, ()) => 10;
/* G 2 */
let optionalAnnot(:a? : int, :b? : int, ()) => 10;
/*H*/
let optionalAliasAnnot(:a aa=?:int, :b bb=?:int, ()) => 10;
/*I: */
let defOptional(:a = 10, :b=10, ()) => 10;
type named = :a:int? => :b:int? => unit => int;
/*J*/
let defOptionalAlias(:a aa=10, :b bb = 10, ()) => 10;
/*K*/
let defOptionalAnnot(:a=10:int, :b = 10:int, ()) => 10;
/*L*/
let defOptionalAliasAnnot(:a aa=10:int, :b bb=10:int, ()) => 10;
/*M: Invoking them - Punned */
let resNotAnnotated = named(:a, :b);
/*N:*/
let resAnnotated: int = named(:a, :b);
/*O: Invoking them */
let resNotAnnotated = named(a~a, b~b);
/*P: Invoking them */
let resAnnotated: int = named(:a a, :b b);
/*Q: Here "punning" works! */
let b = 20;
let resAnnotated = named(:a, :b b);
/*R: Proof that there are no ambiguities with return values being annotated */
let resAnnotated: ty = named(:a, :b);
/*S: Explicitly passed optionals are a nice way to say "use the default value"*/
let explictlyPassed = myOptional(:a None, :b None);
/*T: Annotating the return value of the entire function call */
let explictlyPassedAnnotated: int = myOptional(:a None, :b None);
/*U: Explicitly passing optional with identifier expression */
let a = None;
let explictlyPassed = myOptional(:a, :b None);
let explictlyPassedAnnotated: int = myOptional(:a, :b None);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment