Skip to content

Instantly share code, notes, and snippets.

@sinelaw
Last active September 9, 2015 20:50
Show Gist options
  • Save sinelaw/29a4e4745eec1a522c75 to your computer and use it in GitHub Desktop.
Save sinelaw/29a4e4745eec1a522c75 to your computer and use it in GitHub Desktop.
optional args using polymorphic records + record field constraints
// foo :: { 0: Num, 1: Maybe Num } -> Num
function foo(a, opt_b) {
var b = opt_b == undefined ? 3 : opt_b;
return a + b;
}
// foo here inferred to have this type:
// RowFields r Maybe => { 0: Num | r } -> b
foo(3); // translated to: foo { 0 = 3 | .. }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment