diff --git a/compiler/graindoc/docblock.re b/compiler/graindoc/docblock.re index 2711f06aeb..ccbcd02938 100644 --- a/compiler/graindoc/docblock.re +++ b/compiler/graindoc/docblock.re @@ -207,7 +207,10 @@ let output_for_throws = throws => { let types_for_function = (~ident, vd: Types.value_description) => { switch (Ctype.repr(vd.val_type).desc) { - | TTyArrow(args, returns, _) => (Some(args), Some(returns)) + | TTyArrow(args, returns, _) => ( + Some(List.map(snd, args)), + Some(returns), + ) | _ => (None, None) }; }; diff --git a/compiler/src/formatting/format.re b/compiler/src/formatting/format.re index 63bda8cd2c..958f18a83c 100644 --- a/compiler/src/formatting/format.re +++ b/compiler/src/formatting/format.re @@ -1746,7 +1746,8 @@ and print_type = Doc.group( switch (types) { | [] => Doc.concat([Doc.lparen, Doc.rparen]) - | [t] => print_type(~original_source, ~comments, t) + | [{ptyp_arg_label: Unlabeled, ptyp_arg_type: t}] => + print_type(~original_source, ~comments, t) | _types => Doc.concat([ Doc.lparen, @@ -1756,7 +1757,29 @@ and print_type = Doc.join( ~sep=Doc.concat([Doc.comma, Doc.line]), List.map( - t => print_type(~original_source, ~comments, t), + ({Parsetree.ptyp_arg_label: label, ptyp_arg_type: t}) => { + let label = + switch (label) { + | Asttypes.Unlabeled => Doc.nil + | Labeled(name) => + Doc.concat([ + Doc.text(name.txt), + Doc.text(":"), + Doc.space, + ]) + | Default(name) => + Doc.concat([ + Doc.question, + Doc.text(name.txt), + Doc.text(":"), + Doc.space, + ]) + }; + Doc.concat([ + label, + print_type(~original_source, ~comments, t), + ]); + }, types, ), ), @@ -1851,7 +1874,7 @@ and print_type = and print_application = ( ~expression_parent: expression_parent_type, - ~expressions: list(Parsetree.expression), + ~expressions: list(Parsetree.application_argument), ~original_source: array(string), ~comments: list(Parsetree.comment), func: Parsetree.expression, @@ -1881,7 +1904,7 @@ and print_application = and print_infix_application = ( ~expression_parent: expression_parent_type, - ~expressions: list(Parsetree.expression), + ~expressions: list(Parsetree.application_argument), ~original_source: array(string), ~comments: list(Parsetree.comment), func: Parsetree.expression, @@ -1892,12 +1915,12 @@ and print_infix_application = | [first, second] => let next_comments = Comment_utils.get_comments_between_locations( - ~loc1=first.pexp_loc, - ~loc2=second.pexp_loc, + ~loc1=first.paa_loc, + ~loc2=second.paa_loc, comments, ); - let (_, line, _, _) = Locations.get_raw_pos_info(first.pexp_loc.loc_end); + let (_, line, _, _) = Locations.get_raw_pos_info(first.paa_loc.loc_end); let line_comments = Comment_utils.get_comments_on_line(line, next_comments); @@ -1912,20 +1935,20 @@ and print_infix_application = Comment_utils.single_line_of_comments(line_comments); let left_is_if = - switch (first.pexp_desc) { + switch (first.paa_expr.pexp_desc) { | PExpIf(_) => true | _ => false }; let right_is_if = - switch (second.pexp_desc) { + switch (second.paa_expr.pexp_desc) { | PExpIf(_) => true | _ => false }; let parent_prec = op_precedence(function_name); let left_is_leaf = - switch (first.pexp_desc) { + switch (first.paa_expr.pexp_desc) { | PExpApp(fn, expr) => let child_name = get_function_name(fn); let this_prec = op_precedence(child_name); @@ -1935,7 +1958,7 @@ and print_infix_application = }; let right_is_leaf = - switch (second.pexp_desc) { + switch (second.paa_expr.pexp_desc) { | PExpApp(fn, expr) => let child_name = get_function_name(fn); let this_prec = op_precedence(child_name); @@ -1945,7 +1968,7 @@ and print_infix_application = }; let left_grouping_required = - switch (first.pexp_desc) { + switch (first.paa_expr.pexp_desc) { | PExpApp(fn1, _) => op_precedence(get_function_name(fn1)) < parent_prec | PExpConstant(PConstNumber(PConstNumberRational(_, _))) => @@ -1956,7 +1979,7 @@ and print_infix_application = let right_grouping_required = // the equality check is needed for the value on the right // as we process from the left by default when the same prededence - switch (second.pexp_desc) { + switch (second.paa_expr.pexp_desc) { | PExpApp(fn1, _) => op_precedence(get_function_name(fn1)) <= parent_prec | PExpConstant(PConstNumber(PConstNumberRational(_, _))) => @@ -1967,7 +1990,7 @@ and print_infix_application = // Put parens around different operators for clarity, except // math and logic operations where precedence is well-known let left_is_different_op = - switch (first.pexp_desc) { + switch (first.paa_expr.pexp_desc) { | PExpApp(fn1, _) => let fn = get_function_name(fn1); if (infixop(fn)) { @@ -1990,7 +2013,7 @@ and print_infix_application = ~expression_parent=GenericExpression, ~original_source, ~comments, - first, + first.paa_expr, ); Doc.concat([ Doc.lparen, @@ -2006,7 +2029,7 @@ and print_infix_application = ~expression_parent, ~original_source, ~comments, - first, + first.paa_expr, ); }; @@ -2019,7 +2042,7 @@ and print_infix_application = ~expression_parent=GenericExpression, ~original_source, ~comments, - second, + second.paa_expr, ), ]), Doc.rparen, @@ -2030,7 +2053,7 @@ and print_infix_application = ~expression_parent, ~original_source, ~comments, - second, + second.paa_expr, ), ]); }; @@ -2080,8 +2103,8 @@ and print_infix_application = } and print_arg_lambda = - (~comments, ~original_source, lambda: Parsetree.expression) => { - switch (lambda.pexp_desc) { + (~comments, ~original_source, lambda: Parsetree.application_argument) => { + switch (lambda.paa_expr.pexp_desc) { | PExpLambda(patterns, expression) => let comments_in_expression = Comment_utils.get_comments_inside_location( @@ -2090,7 +2113,7 @@ and print_arg_lambda = ); let raw_args = - print_patterns( + print_lambda_arguments( ~next_loc=expression.pexp_loc, ~comments, ~original_source, @@ -2098,24 +2121,35 @@ and print_arg_lambda = patterns, ); + let label = + switch (lambda.paa_label) { + | Unlabeled => Doc.nil + | Labeled(name) + | Default(name) => Doc.concat([Doc.text(name.txt), Doc.equal]) + }; + let args = - Doc.group( - switch (patterns) { - | [] => Doc.concat([Doc.lparen, raw_args, Doc.rparen]) - | [pat] => - switch (pat.ppat_desc) { - | PPatVar(_) => raw_args - | _ => Doc.group(Doc.concat([Doc.lparen, raw_args, Doc.rparen])) - } - | _patterns => - Doc.concat([ - Doc.lparen, - Doc.indent(Doc.concat([Doc.softLine, raw_args])), - Doc.softLine, - Doc.rparen, - ]) - }, - ); + Doc.concat([ + label, + Doc.group( + switch (patterns) { + | [ + { + pla_label: Labeled(name), + pla_pattern: {ppat_desc: PPatVar(var)}, + }, + ] + when name.txt == var.txt => raw_args + | _patterns => + Doc.concat([ + Doc.lparen, + Doc.indent(Doc.concat([Doc.softLine, raw_args])), + Doc.softLine, + Doc.rparen, + ]) + }, + ), + ]); Doc.group( switch (expression.pexp_desc) { @@ -2208,13 +2242,14 @@ and print_arg_lambda = }; } -and print_arg = (~original_source, ~comments, arg: Parsetree.expression) => { - switch (arg.pexp_desc) { +and print_arg = + (~original_source, ~comments, arg: Parsetree.application_argument) => { + switch (arg.paa_expr.pexp_desc) { | PExpLambda(patterns, expression) => print_arg_lambda(~comments, ~original_source, arg) | _ => Doc.group( - print_expression( + print_application_argument( ~expression_parent=InfixExpression, ~original_source, ~comments, @@ -2228,12 +2263,12 @@ and print_args_with_comments = ( ~comments: list(Parsetree.comment), ~original_source, - args: list(Parsetree.expression), + args: list(Parsetree.application_argument), ) => { - let get_loc = (e: Parsetree.expression) => e.pexp_loc; - let print_item = (~comments, e: Parsetree.expression) => { + let get_loc = (e: Parsetree.application_argument) => e.paa_loc; + let print_item = (~comments, e: Parsetree.application_argument) => { Doc.group( - print_expression( + print_application_argument( ~expression_parent=InfixExpression, ~original_source, ~comments, @@ -2256,7 +2291,7 @@ and print_args_with_comments = } and print_arguments_with_callback_in_first_position = - (~original_source, ~comments, args: list(Parsetree.expression)) => { + (~original_source, ~comments, args: list(Parsetree.application_argument)) => { switch (args) { | [] => Doc.nil | [callback] => @@ -2307,7 +2342,7 @@ and print_arguments_with_callback_in_first_position = } and print_arguments_with_callback_in_last_position = - (~original_source, ~comments, args: list(Parsetree.expression)) => + (~original_source, ~comments, args: list(Parsetree.application_argument)) => switch (args) { | [] => Doc.nil | [expr, callback] => @@ -2349,7 +2384,7 @@ and print_arguments_with_callback_in_last_position = and print_other_application = ( ~expression_parent: expression_parent_type, - ~expressions: list(Parsetree.expression), + ~expressions: list(Parsetree.application_argument), ~original_source: array(string), ~comments: list(Parsetree.comment), func: Parsetree.expression, @@ -2358,7 +2393,7 @@ and print_other_application = switch (expressions) { | [first] when prefixop(function_name) => - switch (first.pexp_desc) { + switch (first.paa_expr.pexp_desc) { | PExpApp(fn, _) => let inner_fn = get_function_name(fn); if (infixop(inner_fn)) { @@ -2366,7 +2401,7 @@ and print_other_application = Doc.text(function_name), Doc.lparen, Doc.group( - print_expression( + print_application_argument( ~expression_parent, ~original_source, ~comments, @@ -2379,7 +2414,7 @@ and print_other_application = Doc.concat([ Doc.text(function_name), Doc.group( - print_expression( + print_application_argument( ~expression_parent, ~original_source, ~comments, @@ -2393,7 +2428,7 @@ and print_other_application = Doc.concat([ Doc.text(function_name), Doc.group( - print_expression( + print_application_argument( ~expression_parent, ~original_source, ~comments, @@ -2423,7 +2458,7 @@ and print_other_application = func, ), Doc.space, - print_expression( + print_application_argument( ~expression_parent=GenericExpression, ~original_source, ~comments, @@ -2435,7 +2470,7 @@ and print_other_application = // look out for special cases of callbacks in first or last position let first_arg_is_callback = - switch (first_expr.pexp_desc) { + switch (first_expr.paa_expr.pexp_desc) { | PExpLambda(_) => true | _ => false }; @@ -2446,7 +2481,7 @@ and print_other_application = | _ => let last_expression = get_last_item_in_list(expressions); - switch (last_expression.pexp_desc) { + switch (last_expression.paa_expr.pexp_desc) { | PExpLambda(_) => true | _ => false }; @@ -2580,6 +2615,118 @@ and print_patterns = }; } +and print_lambda_arguments = + ( + ~next_loc: Location.t, + ~comments: list(Parsetree.comment), + ~original_source: array(string), + ~followed_by_arrow: option(bool)=?, + arguments: list(Parsetree.lambda_argument), + ) => { + let get_loc = (l: Parsetree.lambda_argument) => l.pla_loc; + let print_item = + ( + ~comments, + {pla_pattern: pattern, pla_default: default, pla_loc}: Parsetree.lambda_argument, + ) => { + let pattern_doc = + print_pattern(~original_source, ~comments, ~next_loc, pattern); + let default_doc = + switch (default) { + | None => Doc.nil + | Some(expr) => + Doc.concat([ + Doc.equal, + print_expression( + ~expression_parent=GenericExpression, + ~original_source, + ~comments, + expr, + ), + ]) + }; + + Doc.concat([pattern_doc, default_doc]); + }; + + let comments_in_scope = + Comment_utils.get_comments_before_location(~location=next_loc, comments); + + switch (arguments) { + | [] => Doc.nil + | _ => + let items = + item_iterator( + ~get_loc, + ~print_item, + ~comments=comments_in_scope, + ~followed_by_arrow?, + ~iterated_item=IteratedPatterns, + arguments, + ); + Doc.join(~sep=Doc.line, items); + }; +} + +and print_application_argument = + ( + ~comments: list(Parsetree.comment), + ~expression_parent: expression_parent_type, + ~original_source: array(string), + argument: Parsetree.application_argument, + ) => { + let expr_doc = + print_expression( + ~expression_parent, + ~original_source, + ~comments, + argument.paa_expr, + ); + switch (argument.paa_label, argument.paa_expr.pexp_desc) { + | (Asttypes.Unlabeled, _) => expr_doc + | (Labeled(name) | Default(name), _) => + Doc.concat([Doc.text(name.txt), Doc.equal, expr_doc]) + }; +} + +and print_application_arguments = + ( + ~next_loc: Location.t, + ~comments: list(Parsetree.comment), + ~expression_parent: expression_parent_type, + ~original_source: array(string), + ~followed_by_arrow: option(bool)=?, + arguments: list(Parsetree.application_argument), + ) => { + let get_loc = (l: Parsetree.application_argument) => l.paa_loc; + let print_item = (~comments, argument: Parsetree.application_argument) => { + print_application_argument( + ~comments, + ~expression_parent, + ~original_source, + argument, + ); + }; + + let comments_in_scope = + Comment_utils.get_comments_before_location(~location=next_loc, comments); + + switch (arguments) { + | [] => Doc.nil + | _ => + let items = + item_iterator( + ~get_loc, + ~print_item, + ~comments=comments_in_scope, + ~followed_by_arrow?, + ~iterated_item=IteratedPatterns, + arguments, + ); + Doc.join(~sep=Doc.line, items); + }; +} + and paren_wrap_patterns = ( ~wrapper: Location.t, @@ -2587,10 +2734,10 @@ and paren_wrap_patterns = ~comments: list(Parsetree.comment), ~original_source: array(string), ~followed_by_arrow: bool, - patterns: list(Parsetree.pattern), + patterns: list(Parsetree.lambda_argument), ) => { let args = - print_patterns( + print_lambda_arguments( ~next_loc, ~comments, ~original_source, @@ -2600,11 +2747,8 @@ and paren_wrap_patterns = switch (patterns) { | [] => Doc.concat([Doc.lparen, args, Doc.rparen]) - | [pat] => - switch (pat.ppat_desc) { - | PPatVar(_) => args - | _ => Doc.concat([Doc.lparen, args, Doc.rparen]) - } + | [{pla_label: Labeled(name), pla_pattern: {ppat_desc: PPatVar(var)}}] + when name.txt == var.txt => args | _patterns => let trail_sep = Doc.ifBreaks(Doc.comma, Doc.nil); @@ -3639,6 +3783,17 @@ and print_expression_inner = ~location=expr.pexp_loc, comments, ); + // Treat constructors as function calls + let expressions = + List.map( + expr => + { + Parsetree.paa_label: Unlabeled, + paa_expr: expr, + paa_loc: expr.pexp_loc, + }, + expressions, + ); print_application( ~expression_parent, ~expressions, @@ -3906,7 +4061,7 @@ and print_assignment = (~original_source, ~comments, left, value) => { let left_matches_first = switch (expressions) { | [expr, ...remainder] => - print_expression( + print_application_argument( ~expression_parent=GenericExpression, ~original_source, ~comments, @@ -3933,16 +4088,16 @@ and print_assignment = (~original_source, ~comments, left, value) => { raise(IllegalParse("Sugared op needs at least one expression")) | [expression] => let expr = - print_expression( + print_application_argument( ~expression_parent=GenericExpression, ~original_source, ~comments, expression, ); - switch (expression.pexp_desc) { + switch (expression.paa_expr.pexp_desc) { | PExpIf(_) => Doc.indent( - print_expression( + print_application_argument( ~expression_parent=GenericExpression, ~original_source, ~comments, @@ -3953,16 +4108,16 @@ and print_assignment = (~original_source, ~comments, left, value) => { }; | [expression1, expression2, ...rest] => let expr = - print_expression( + print_application_argument( ~expression_parent=GenericExpression, ~original_source, ~comments, expression2, ); - switch (expression2.pexp_desc) { + switch (expression2.paa_expr.pexp_desc) { | PExpIf(_) => Doc.indent( - print_expression( + print_application_argument( ~expression_parent=GenericExpression, ~original_source, ~comments, diff --git a/compiler/src/middle_end/linearize.re b/compiler/src/middle_end/linearize.re index 57f8a94d16..49429db9a7 100644 --- a/compiler/src/middle_end/linearize.re +++ b/compiler/src/middle_end/linearize.re @@ -164,6 +164,31 @@ let convert_binds = anf_binds => { List.fold_left(convert_bind, ans, top_binds); }; +// reorder arguments according to labels +let reorder_arguments = (args, order) => { + let rec reorder = (reordered_args, args, order) => { + let rec extract_label = (l, arg) => { + switch (arg) { + | [] => failwith("Impossible: no argument matching label") + | [(argl, arg), ...rest_args] when Btype.same_label_name(argl, l) => ( + arg, + rest_args, + ) + | [arg, ...rest_args] => + let (res, rest_args) = extract_label(l, rest_args); + (res, [arg, ...rest_args]); + }; + }; + switch (order) { + | [] => reordered_args + | [tyl, ...order] => + let (value, args) = extract_label(tyl, args); + reorder([value, ...reordered_args], args, order); + }; + }; + List.rev(reorder([], args, order)); +}; + let transl_const = (~loc=Location.dummy_loc, ~env=Env.empty, c: Types.constant) : Either.t(imm_expression, (ident, list(anf_bind))) => { @@ -516,21 +541,26 @@ let rec transl_imm = | TExpApp( {exp_desc: TExpIdent(_, _, {val_kind: TValPrim("@throw")})}, _, + _, ) => let (ans, ans_setup) = transl_comp_expression(e); (Imm.trap(~loc, ~env, ()), ans_setup @ [BSeq(ans)]); - | TExpApp({exp_desc: TExpIdent(_, _, {val_kind: TValPrim(prim)})}, args) => + | TExpApp( + {exp_desc: TExpIdent(_, _, {val_kind: TValPrim(prim)})}, + _, + args, + ) => let (imm, setup) = Translprim.( switch (PrimMap.find_opt(prim_map, prim), args) { | (Some(Primitive0(prim)), []) => transl_imm({...e, exp_desc: TExpPrim0(prim)}) - | (Some(Primitive1(prim)), [arg]) => + | (Some(Primitive1(prim)), [(_, arg)]) => transl_imm({...e, exp_desc: TExpPrim1(prim, arg)}) - | (Some(Primitive2(prim)), [arg1, arg2]) => + | (Some(Primitive2(prim)), [(_, arg1), (_, arg2)]) => transl_imm({...e, exp_desc: TExpPrim2(prim, arg1, arg2)}) | (Some(PrimitiveN(prim)), args) => - transl_imm({...e, exp_desc: TExpPrimN(prim, args)}) + transl_imm({...e, exp_desc: TExpPrimN(prim, List.map(snd, args))}) | (Some(_), _) => failwith("transl_imm: invalid primitive arity") | (None, _) => failwith("transl_imm: unknown primitive") } @@ -543,10 +573,20 @@ let rec transl_imm = } else { (imm, setup); }; - | TExpApp(func, args) => + | TExpApp(func, order, args) => let tmp = gensym("app"); let (new_func, func_setup) = transl_imm(func); - let (new_args, new_setup) = List.split(List.map(transl_imm, args)); + let (new_args, new_setup) = + List.split( + List.map( + ((l, arg)) => { + let (arg, setup) = transl_imm(arg); + ((l, arg), setup); + }, + args, + ), + ); + let new_args = reorder_arguments(new_args, order); ( Imm.id(~loc, ~env, tmp), (func_setup @ List.concat(new_setup)) @@ -1279,10 +1319,21 @@ and transl_comp_expression = (Comp.return(~loc, ~env, value_imm), value_setup); | TExpApp( {exp_desc: TExpIdent(_, _, {val_kind: TValPrim("@throw")})} as func, + order, args, ) => let (new_func, func_setup) = transl_imm(func); - let (new_args, new_setup) = List.split(List.map(transl_imm, args)); + let (new_args, new_setup) = + List.split( + List.map( + ((l, arg)) => { + let (arg, setup) = transl_imm(arg); + ((l, arg), setup); + }, + args, + ), + ); + let new_args = reorder_arguments(new_args, order); let (ans, ans_setup) = ( Comp.app( ~loc, @@ -1299,19 +1350,26 @@ and transl_comp_expression = Comp.imm(~attributes, ~allocation_type, ~env, Imm.trap(~loc, ~env, ())), ans_setup @ [BSeq(ans)], ); - | TExpApp({exp_desc: TExpIdent(_, _, {val_kind: TValPrim(prim)})}, args) => + | TExpApp( + {exp_desc: TExpIdent(_, _, {val_kind: TValPrim(prim)})}, + _, + args, + ) => if (tail) { let (imm, setup) = Translprim.( switch (PrimMap.find_opt(prim_map, prim), args) { | (Some(Primitive0(prim)), []) => transl_imm({...e, exp_desc: TExpPrim0(prim)}) - | (Some(Primitive1(prim)), [arg]) => + | (Some(Primitive1(prim)), [(_, arg)]) => transl_imm({...e, exp_desc: TExpPrim1(prim, arg)}) - | (Some(Primitive2(prim)), [arg1, arg2]) => + | (Some(Primitive2(prim)), [(_, arg1), (_, arg2)]) => transl_imm({...e, exp_desc: TExpPrim2(prim, arg1, arg2)}) | (Some(PrimitiveN(prim)), args) => - transl_imm({...e, exp_desc: TExpPrimN(prim, args)}) + transl_imm({ + ...e, + exp_desc: TExpPrimN(prim, List.map(snd, args)), + }) | (Some(_), _) => failwith("transl_comp_expression: invalid primitive arity") | (None, _) => @@ -1324,24 +1382,37 @@ and transl_comp_expression = switch (PrimMap.find_opt(prim_map, prim), args) { | (Some(Primitive0(prim)), []) => transl_comp_expression({...e, exp_desc: TExpPrim0(prim)}) - | (Some(Primitive1(prim)), [arg]) => + | (Some(Primitive1(prim)), [(_, arg)]) => transl_comp_expression({...e, exp_desc: TExpPrim1(prim, arg)}) - | (Some(Primitive2(prim)), [arg1, arg2]) => + | (Some(Primitive2(prim)), [(_, arg1), (_, arg2)]) => transl_comp_expression({ ...e, exp_desc: TExpPrim2(prim, arg1, arg2), }) | (Some(PrimitiveN(prim)), args) => - transl_comp_expression({...e, exp_desc: TExpPrimN(prim, args)}) + transl_comp_expression({ + ...e, + exp_desc: TExpPrimN(prim, List.map(snd, args)), + }) | (Some(_), _) => failwith("transl_comp_expression: invalid primitive arity") | (None, _) => failwith("transl_comp_expression: unknown primitive") } ); } - | TExpApp(func, args) => + | TExpApp(func, order, args) => let (new_func, func_setup) = transl_imm(func); - let (new_args, new_setup) = List.split(List.map(transl_imm, args)); + let (new_args, new_setup) = + List.split( + List.map( + ((l, arg)) => { + let (arg, setup) = transl_imm(arg); + ((l, arg), setup); + }, + args, + ), + ); + let new_args = reorder_arguments(new_args, order); ( Comp.app( ~loc, diff --git a/compiler/src/parsing/ast_helper.re b/compiler/src/parsing/ast_helper.re index f4468d7bcb..5bb766262f 100644 --- a/compiler/src/parsing/ast_helper.re +++ b/compiler/src/parsing/ast_helper.re @@ -369,38 +369,46 @@ module Expression = { // and if you choose to shift then 1 / foo would always be a syntax error // because the parser would expect a number). It's easier to just parse it // as division and have this action decide that it's actually a rational. - let binop = (~loc=?, ~attributes=?, a, b) => { + let binop = (~loc=?, ~attributes=?, f, a, b) => { // Locations of nested binops are difficult to compute in the parser so we // just set the location manually here let loc = Location.( Option.map( loc => - switch (b) { - | [{pexp_loc: {loc_start}}, {pexp_loc: {loc_end}}] => { + switch (a, b) { + | ({pexp_loc: {loc_start}}, {pexp_loc: {loc_end}}) => { ...loc, loc_start, loc_end, } - | _ => failwith("Impossible: not a binop") }, loc, ) ); - switch (a, b) { + switch (f, a, b) { | ( {pexp_desc: PExpId({txt: IdentName({txt: "/"})})}, - [ - {pexp_desc: PExpConstant(PConstNumber(PConstNumberInt(x)))}, - {pexp_desc: PExpConstant(PConstNumber(PConstNumberInt(y)))}, - ], + {pexp_desc: PExpConstant(PConstNumber(PConstNumberInt(x)))}, + {pexp_desc: PExpConstant(PConstNumber(PConstNumberInt(y)))}, ) => constant( ~loc?, ~attributes?, PConstNumber(PConstNumberRational(x, y)), ) - | _ => mk(~loc?, ~attributes?, PExpApp(a, b)) + | _ => + mk( + ~loc?, + ~attributes?, + PExpApp( + f, + [ + {paa_label: Unlabeled, paa_expr: a, paa_loc: a.pexp_loc}, + {paa_label: Unlabeled, paa_expr: b, paa_loc: b.pexp_loc}, + ], + ), + ) }; }; let block = (~loc=?, ~attributes=?, a) => @@ -510,6 +518,45 @@ module IncludeDeclaration = { }; }; +module TypeArgument = { + let mk = (~loc, label, typ) => { + {ptyp_arg_label: label, ptyp_arg_type: typ, ptyp_arg_loc: loc}; + }; +}; + +module LambdaArgument = { + let mk = (~loc, pattern, default) => { + open Asttypes; + let label = + switch (pattern.ppat_desc) { + | PPatVar(name) + | PPatAlias({ppat_desc: PPatVar(name)}, _) + | PPatAlias(_, name) + | PPatConstraint( + { + ppat_desc: + PPatVar(name) | PPatAlias({ppat_desc: PPatVar(name)}, _) | + PPatAlias(_, name), + }, + _, + ) => + Some(name) + | _ => None + }; + let pla_label = + switch (label, default) { + | (Some(name), Some(_)) => Default(name) + | (Some(name), None) => Labeled(name) + | (None, None) => Unlabeled + | (None, Some(_)) => + raise(SyntaxError(loc, "Default arguments must be named.")) + }; + let pla_pattern = pattern; + let pla_default = default; + {pla_label, pla_default, pla_pattern, pla_loc: loc}; + }; +}; + module ModuleDeclaration = { let mk = (~loc, name, stmts) => { {pmod_name: name, pmod_stmts: stmts, pmod_loc: loc}; diff --git a/compiler/src/parsing/ast_helper.rei b/compiler/src/parsing/ast_helper.rei index 03c89fbeb5..f77e02f614 100644 --- a/compiler/src/parsing/ast_helper.rei +++ b/compiler/src/parsing/ast_helper.rei @@ -61,7 +61,8 @@ module Type: { let mk: (~loc: loc=?, parsed_type_desc) => parsed_type; let any: (~loc: loc=?, unit) => parsed_type; let var: (~loc: loc=?, string) => parsed_type; - let arrow: (~loc: loc=?, list(parsed_type), parsed_type) => parsed_type; + let arrow: + (~loc: loc=?, list(parsed_type_argument), parsed_type) => parsed_type; let tuple: (~loc: loc=?, list(parsed_type)) => parsed_type; let constr: (~loc: loc=?, id, list(parsed_type)) => parsed_type; let poly: (~loc: loc=?, list(str), parsed_type) => parsed_type; @@ -227,10 +228,20 @@ module Expression: { (~loc: loc=?, ~attributes: attributes=?, expression, expression) => expression; let lambda: - (~loc: loc=?, ~attributes: attributes=?, list(pattern), expression) => + ( + ~loc: loc=?, + ~attributes: attributes=?, + list(lambda_argument), + expression + ) => expression; let apply: - (~loc: loc=?, ~attributes: attributes=?, expression, list(expression)) => + ( + ~loc: loc=?, + ~attributes: attributes=?, + expression, + list(application_argument) + ) => expression; let construct: (~loc: loc, ~attributes: attributes=?, id, constructor_expression) => @@ -243,7 +254,13 @@ module Expression: { let record_construct: (~loc: loc, ~attributes: attributes=?, id, list(recorditem)) => expression; let binop: - (~loc: loc=?, ~attributes: attributes=?, expression, list(expression)) => + ( + ~loc: loc=?, + ~attributes: attributes=?, + expression, + expression, + expression + ) => expression; let block: (~loc: loc=?, ~attributes: attributes=?, list(expression)) => expression; @@ -333,6 +350,15 @@ module IncludeDeclaration: { let mk: (~loc: loc, str, option(str)) => include_declaration; }; +module TypeArgument: { + let mk: + (~loc: loc, Asttypes.argument_label, parsed_type) => parsed_type_argument; +}; + +module LambdaArgument: { + let mk: (~loc: loc, pattern, option(expression)) => lambda_argument; +}; + module ModuleDeclaration: { let mk: (~loc: loc, str, list(toplevel_stmt)) => module_declaration; }; diff --git a/compiler/src/parsing/ast_mapper.re b/compiler/src/parsing/ast_mapper.re index a92ac134fd..79dfa74650 100644 --- a/compiler/src/parsing/ast_mapper.re +++ b/compiler/src/parsing/ast_mapper.re @@ -133,7 +133,16 @@ module E = { lambda( ~loc, ~attributes, - List.map(sub.pat(sub), pl), + List.map( + arg => + { + pla_label: arg.pla_label, + pla_pattern: sub.pat(sub, arg.pla_pattern), + pla_default: Option.map(sub.expr(sub), arg.pla_default), + pla_loc: sub.location(sub, arg.pla_loc), + }, + pl, + ), sub.expr(sub, e), ) | PExpApp(e, el) => @@ -141,7 +150,15 @@ module E = { ~loc, ~attributes, sub.expr(sub, e), - List.map(sub.expr(sub), el), + List.map( + arg => + { + paa_label: arg.paa_label, + paa_expr: sub.expr(sub, arg.paa_expr), + paa_loc: sub.location(sub, arg.paa_loc), + }, + el, + ), ) | PExpConstruct(id, e) => construct( @@ -325,7 +342,19 @@ module T = { | PTyAny => any(~loc, ()) | PTyVar(v) => var(~loc, v) | PTyArrow(args, ret) => - arrow(~loc, List.map(sub.typ(sub), args), sub.typ(sub, ret)) + arrow( + ~loc, + List.map( + arg => + { + ptyp_arg_label: arg.ptyp_arg_label, + ptyp_arg_type: sub.typ(sub, arg.ptyp_arg_type), + ptyp_arg_loc: sub.location(sub, arg.ptyp_arg_loc), + }, + args, + ), + sub.typ(sub, ret), + ) | PTyTuple(ts) => tuple(~loc, List.map(sub.typ(sub), ts)) | PTyConstr(name, ts) => constr(~loc, map_identifier(sub, name), List.map(sub.typ(sub), ts)) diff --git a/compiler/src/parsing/asttypes.re b/compiler/src/parsing/asttypes.re index b8fdbed274..01eec717c1 100644 --- a/compiler/src/parsing/asttypes.re +++ b/compiler/src/parsing/asttypes.re @@ -115,3 +115,9 @@ type attribute = (loc(string), list(loc(string))); [@deriving (sexp, yojson)] type attributes = list(attribute); + +[@deriving (sexp, yojson)] +type argument_label = + | Unlabeled + | Labeled(loc(string)) + | Default(loc(string)); diff --git a/compiler/src/parsing/lexer.re b/compiler/src/parsing/lexer.re index 815ffc5520..8b3d2aed49 100644 --- a/compiler/src/parsing/lexer.re +++ b/compiler/src/parsing/lexer.re @@ -322,6 +322,7 @@ let rec token = lexbuf => { | "::" => positioned(COLONCOLON) | ":=" => positioned(GETS) | ":" => positioned(COLON) + | "?" => positioned(QUESTION) | "=" => positioned(EQUAL) | "," => positioned(COMMA) | ";" => positioned(SEMI) diff --git a/compiler/src/parsing/parser.messages b/compiler/src/parsing/parser.messages index 5f3277b613..651e341920 100644 --- a/compiler/src/parsing/parser.messages +++ b/compiler/src/parsing/parser.messages @@ -153,6 +153,16 @@ program: MODULE UIDENT EOL FOREIGN WASM YIELD ## The known suffix of the stack is as follows: ## FOREIGN WASM ## +program: MODULE UIDENT EOL UIDENT COLON FUN LPAREN QUESTION YIELD +## +## Ends in an error in state: 198. +## +## arg_typ -> QUESTION . LIDENT COLON typ [ RPAREN EOL COMMA ] +## arg_typ -> QUESTION . LIDENT COLON eols typ [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## QUESTION +## Expected a lowercase identifier. @@ -182,6 +192,74 @@ program: MODULE UIDENT EOL FOREIGN WASM LIDENT COLON YIELD Expected the type of the foreign value. +program: MODULE UIDENT EOL UIDENT COLON FUN LPAREN QUESTION LIDENT YIELD +## +## Ends in an error in state: 199. +## +## arg_typ -> QUESTION LIDENT . COLON typ [ RPAREN EOL COMMA ] +## arg_typ -> QUESTION LIDENT . COLON eols typ [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## QUESTION LIDENT +## + +Expected a colon followed by the type of the argument. + +program: MODULE UIDENT EOL UIDENT COLON FUN LPAREN QUESTION LIDENT COLON YIELD +## +## Ends in an error in state: 200. +## +## arg_typ -> QUESTION LIDENT COLON . typ [ RPAREN EOL COMMA ] +## arg_typ -> QUESTION LIDENT COLON . eols typ [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## QUESTION LIDENT COLON +## +program: MODULE UIDENT EOL UIDENT COLON FUN LPAREN QUESTION LIDENT COLON EOL YIELD +## +## Ends in an error in state: 202. +## +## arg_typ -> QUESTION LIDENT COLON eols . typ [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## QUESTION LIDENT COLON eols +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 3, spurious reduction of production nonempty_list(eol) -> EOL +## In state 6, spurious reduction of production eols -> nonempty_list(eol) +## +program: MODULE UIDENT EOL UIDENT COLON FUN LPAREN LIDENT COLON YIELD +## +## Ends in an error in state: 205. +## +## arg_typ -> LIDENT COLON . typ [ RPAREN EOL COMMA ] +## arg_typ -> LIDENT COLON . eols typ [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## LIDENT COLON +## +program: MODULE UIDENT EOL UIDENT COLON FUN LPAREN LIDENT COLON EOL YIELD +## +## Ends in an error in state: 207. +## +## arg_typ -> LIDENT COLON eols . typ [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## LIDENT COLON eols +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 3, spurious reduction of production nonempty_list(eol) -> EOL +## In state 6, spurious reduction of production eols -> nonempty_list(eol) +## + +Expected the type of the argument. + program: MODULE UIDENT EOL FOREIGN WASM LIDENT COLON UIDENT AS YIELD ## ## Ends in an error in state: 750. @@ -1206,6 +1284,24 @@ program: EOL MODULE UIDENT EOL YIELD ## In state 6, spurious reduction of production eols -> nonempty_list(eol) ## In state 398, spurious reduction of production eos -> eols ## +program: MODULE UIDENT EOL BIGINT LPAREN LIDENT EQUAL YIELD +## +## Ends in an error in state: 475. +## +## app_arg -> id_str EQUAL . expr [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## id_str EQUAL +## +program: MODULE UIDENT EOL FUN LPAREN NUMBER_INT EQUAL YIELD +## +## Ends in an error in state: 652. +## +## arg_default -> EQUAL . non_stmt_expr [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## EQUAL +## Expected an expression. @@ -2688,9 +2784,9 @@ program: MODULE UIDENT EOL FUN LPAREN WASMI64 COMMA EOL WASMI64 WHILE ## The known suffix of the stack is as follows: ## lseparated_nonempty_list_inner(comma,pattern) comma pattern ## -program: MODULE UIDENT EOL FUN LPAREN WASMI64 WHILE +program: MODULE UIDENT EOL LET LBRACKRCARET NUMBER_INT YIELD ## -## Ends in an error in state: 363. +## Ends in an error in state: 350. ## ## lseparated_nonempty_list_inner(comma,pattern) -> pattern . [ RPAREN RBRACK EOL COMMA ] ## pattern -> pattern . COLON typ [ RPAREN RBRACK PIPE EOL COMMA COLON AS ] @@ -2703,50 +2799,58 @@ program: MODULE UIDENT EOL FUN LPAREN WASMI64 WHILE ## The known suffix of the stack is as follows: ## pattern ## - -Expected a type annotation, a comma followed by more patterns, `)`, or `]`. - -program: MODULE UIDENT EOL FUN LPAREN WASMI64 COMMA EOL WHILE +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 358, spurious reduction of production const -> option(DASH) NUMBER_INT +## In state 397, spurious reduction of production pattern -> const ## -## Ends in an error in state: 396. +program: MODULE UIDENT EOL LET LBRACKRCARET NUMBER_INT COMMA NUMBER_INT YIELD ## -## lseparated_nonempty_list_inner(comma,pattern) -> lseparated_nonempty_list_inner(comma,pattern) comma . pattern [ RPAREN RBRACK EOL COMMA ] -## option(comma) -> comma . [ RPAREN RBRACK EOL ] +## Ends in an error in state: 372. +## +## lseparated_nonempty_list_inner(comma,pattern) -> lseparated_nonempty_list_inner(comma,pattern) comma pattern . [ RPAREN RBRACK EOL COMMA ] +## pattern -> pattern . COLON typ [ RPAREN RBRACK PIPE EOL COMMA COLON AS ] +## pattern -> pattern . COLON eols typ [ RPAREN RBRACK PIPE EOL COMMA COLON AS ] +## pattern -> pattern . PIPE pattern [ RPAREN RBRACK PIPE EOL COMMA COLON AS ] +## pattern -> pattern . PIPE eols pattern [ RPAREN RBRACK PIPE EOL COMMA COLON AS ] +## pattern -> pattern . AS id_str [ RPAREN RBRACK PIPE EOL COMMA COLON AS ] +## pattern -> pattern . AS eols id_str [ RPAREN RBRACK PIPE EOL COMMA COLON AS ] ## ## The known suffix of the stack is as follows: -## lseparated_nonempty_list_inner(comma,pattern) comma +## lseparated_nonempty_list_inner(comma,pattern) comma pattern ## ## WARNING: This example involves spurious reductions. ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 3, spurious reduction of production nonempty_list(eol) -> EOL -## In state 5, spurious reduction of production eols -> nonempty_list(eol) -## In state 96, spurious reduction of production comma -> COMMA eols +## In state 358, spurious reduction of production const -> option(DASH) NUMBER_INT +## In state 397, spurious reduction of production pattern -> const ## -Expected another pattern, `)`, or `]`. +Expected a type annotation, a comma followed by more patterns, `)`, or `]`. -program: MODULE UIDENT EOL FUN LPAREN WASMI64 RBRACK +program: MODULE UIDENT EOL FUN LPAREN WASMI64 COMMA EOL WHILE ## -## Ends in an error in state: 749. +## Ends in an error in state: 396. ## -## lam_expr -> FUN lparen option(patterns) . rparen thickarrow expr [ THICKARROW STAR SLASH SEMI RPAREN RCARET RBRACK RBRACE PIPE LCARET INFIX_90 INFIX_80 INFIX_70 INFIX_60 INFIX_50 INFIX_40 INFIX_30 INFIX_120 INFIX_110 INFIX_100 EOL EOF ELSE DASH COMMA COLON ] +## lseparated_nonempty_list_inner(comma,pattern) -> lseparated_nonempty_list_inner(comma,pattern) comma . pattern [ RPAREN RBRACK EOL COMMA ] +## option(comma) -> comma . [ RPAREN RBRACK EOL ] ## ## The known suffix of the stack is as follows: -## FUN lparen option(patterns) +## lseparated_nonempty_list_inner(comma,pattern) comma ## ## WARNING: This example involves spurious reductions. ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 363, spurious reduction of production lseparated_nonempty_list_inner(comma,pattern) -> pattern -## In state 394, spurious reduction of production option(comma) -> -## In state 395, spurious reduction of production patterns -> lseparated_nonempty_list_inner(comma,pattern) option(comma) -## In state 748, spurious reduction of production option(patterns) -> patterns +## In state 3, spurious reduction of production nonempty_list(eol) -> EOL +## In state 5, spurious reduction of production eols -> nonempty_list(eol) +## In state 96, spurious reduction of production comma -> COMMA eols ## -Expected `)` to complete the function arguments. +Expected another pattern, `)`, or `]`. program: MODULE UIDENT EOL UIDENT LPAREN COMMA WHILE ## @@ -4622,6 +4726,22 @@ program: MODULE UIDENT EOL MATCH LPAREN WASMI64 RPAREN LBRACE WHILE ## may provide an INCOMPLETE view of the future (what was expected next). ## In state 21, spurious reduction of production lbrace -> LBRACE ## +program: MODULE UIDENT EOL LET LBRACKRCARET NUMBER_INT COMMA YIELD +## +## Ends in an error in state: 383. +## +## lseparated_nonempty_list_inner(comma,pattern) -> lseparated_nonempty_list_inner(comma,pattern) comma . pattern [ RPAREN RBRACK EOL COMMA ] +## option(comma) -> comma . [ RPAREN RBRACK EOL ] +## +## The known suffix of the stack is as follows: +## lseparated_nonempty_list_inner(comma,pattern) comma +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 65, spurious reduction of production comma -> COMMA +## Expected a pattern. @@ -5834,6 +5954,22 @@ program: MODULE UIDENT EOL WASMI64 COLON FUN LPAREN WHILE ## may provide an INCOMPLETE view of the future (what was expected next). ## In state 2, spurious reduction of production lparen -> LPAREN ## +program: MODULE UIDENT EOL UIDENT COLON FUN LPAREN LIDENT COMMA YIELD +## +## Ends in an error in state: 216. +## +## lseparated_nonempty_list_inner(comma,arg_typ) -> lseparated_nonempty_list_inner(comma,arg_typ) comma . arg_typ [ RPAREN EOL COMMA ] +## option(comma) -> comma . [ RPAREN EOL ] +## +## The known suffix of the stack is as follows: +## lseparated_nonempty_list_inner(comma,arg_typ) comma +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 65, spurious reduction of production comma -> COMMA +## Expected a comma-separated list of types or an immediate `)` for a function type with no arguments. @@ -6093,6 +6229,35 @@ program: MODULE UIDENT EOL ENUM UIDENT LBRACE UIDENT LPAREN RPAREN YIELD Expected a comma followed by more constructors or `}` to complete the enum declaration. +program: MODULE UIDENT EOL FUN LPAREN NUMBER_INT EQUAL UIDENT YIELD +## +## Ends in an error in state: 660. +## +## lam_args -> lseparated_nonempty_list_inner(comma,lam_arg) . option(comma) [ RPAREN EOL ] +## lseparated_nonempty_list_inner(comma,lam_arg) -> lseparated_nonempty_list_inner(comma,lam_arg) . comma lam_arg [ RPAREN EOL COMMA ] +## +## The known suffix of the stack is as follows: +## lseparated_nonempty_list_inner(comma,lam_arg) +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 225, spurious reduction of production qualified_uid -> lseparated_nonempty_list_inner(dot,type_id_str) +## In state 128, spurious reduction of production construct_expr -> qualified_uid +## In state 271, spurious reduction of production left_accessor_expr -> construct_expr +## In state 246, spurious reduction of production non_assign_expr -> left_accessor_expr +## In state 223, spurious reduction of production non_binop_expr -> non_assign_expr +## In state 160, spurious reduction of production annotated_expr -> non_binop_expr +## In state 280, spurious reduction of production non_stmt_expr -> annotated_expr +## In state 653, spurious reduction of production arg_default -> EQUAL non_stmt_expr +## In state 655, spurious reduction of production option(arg_default) -> arg_default +## In state 654, spurious reduction of production lam_arg -> pattern option(arg_default) +## In state 665, spurious reduction of production lseparated_nonempty_list_inner(comma,lam_arg) -> lam_arg +## + +Expected a comma-separated list of arguments or `)` to complete the function arguments. + program: MODULE UIDENT EOL WHILE LPAREN UNDERSCORE ## ## Ends in an error in state: 7. diff --git a/compiler/src/parsing/parser.mly b/compiler/src/parsing/parser.mly index f7947b2eaf..ae41c2f7f1 100644 --- a/compiler/src/parsing/parser.mly +++ b/compiler/src/parsing/parser.mly @@ -23,7 +23,7 @@ module Grain_parsing = struct end %token THICKARROW ARROW %token EQUAL GETS %token UNDERSCORE -%token COLON DOT ELLIPSIS +%token COLON QUESTION DOT ELLIPSIS %token ASSERT FAIL EXCEPTION THROW @@ -64,7 +64,7 @@ module Grain_parsing = struct end %left INFIX_110 DASH %left INFIX_120 STAR SLASH -%right SEMI EOL COMMA DOT COLON LPAREN +%right SEMI EOL COMMA DOT COLON LPAREN EQUAL %nonassoc _if %nonassoc ELSE @@ -103,8 +103,11 @@ module Grain_parsing = struct end const pattern qualified_uid + qualified_lid value_binds construct_expr + app_arg + arg_default %% @@ -240,8 +243,8 @@ annotated_expr: | non_binop_expr colon typ { Expression.constraint_ ~loc:(to_loc $loc) $1 $3 } binop_expr: - | non_stmt_expr infix_op opt_eols non_stmt_expr { Expression.binop ~loc:(to_loc $loc) (mkid_expr $loc($2) [mkstr $loc($2) $2]) [$1; $4] } - | non_stmt_expr rcaret_rcaret_op opt_eols non_stmt_expr %prec INFIX_100 { Expression.binop ~loc:(to_loc $loc) (mkid_expr $loc($2) [mkstr $loc($2) $2]) [$1; $4] } + | non_stmt_expr infix_op opt_eols non_stmt_expr { Expression.binop ~loc:(to_loc $loc) (mkid_expr $loc($2) [mkstr $loc($2) $2]) $1 $4 } + | non_stmt_expr rcaret_rcaret_op opt_eols non_stmt_expr %prec INFIX_100 { Expression.binop ~loc:(to_loc $loc) (mkid_expr $loc($2) [mkstr $loc($2) $2]) $1 $4 } ellipsis_prefix(X): | ELLIPSIS X {$2} @@ -295,17 +298,25 @@ data_typ: | qualified_uid %prec _below_infix { Type.constr ~loc:(to_loc $loc) $1 [] } typ: - | data_typ arrow typ { Type.arrow ~loc:(to_loc $loc) [$1] $3 } - | FUN LIDENT arrow typ { Type.arrow ~loc:(to_loc $loc) [(Type.var $2)] $4 } - | FUN lparen typs? rparen arrow typ { Type.arrow ~loc:(to_loc $loc) (Option.value ~default:[] $3) $6 } + | data_typ arrow typ { Type.arrow ~loc:(to_loc $loc) [TypeArgument.mk ~loc:(to_loc $loc($1)) Unlabeled $1] $3 } + | FUN LIDENT arrow typ { Type.arrow ~loc:(to_loc $loc) [TypeArgument.mk ~loc:(to_loc $loc($2)) Unlabeled (Type.var $2)] $4 } + | FUN lparen arg_typs? rparen arrow typ { Type.arrow ~loc:(to_loc $loc) (Option.value ~default:[] $3) $6 } | lparen tuple_typs rparen { Type.tuple ~loc:(to_loc $loc) $2 } | lparen typ rparen { $2 } | LIDENT { Type.var ~loc:(to_loc $loc) $1 } | data_typ { $1 } +arg_typ: + | LIDENT colon typ { TypeArgument.mk ~loc:(to_loc $loc) (Labeled (mkstr $loc($1) $1)) $3 } + | QUESTION LIDENT colon typ { TypeArgument.mk ~loc:(to_loc $loc) (Default (mkstr $loc($2) $2)) $4 } + | typ { TypeArgument.mk ~loc:(to_loc $loc) Unlabeled $1 } + typs: | lseparated_nonempty_list(comma, typ) comma? { $1 } +arg_typs: + | lseparated_nonempty_list(comma, arg_typ) comma? { $1 } + %inline tuple_typ_ending: | ioption(eols) lseparated_nonempty_list(comma, typ) ioption(comma) { $2 } @@ -402,13 +413,17 @@ data_declaration: | RECORD UIDENT id_vec? data_labels { DataDeclaration.record ~loc:(to_loc $loc) (mkstr $loc($2) $2) (Option.value ~default:[] $3) $4 } unop_expr: - | prefix_op non_assign_expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) $1]) [$2] } + | prefix_op non_assign_expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) $1]) [{paa_label=Unlabeled; paa_expr=$2; paa_loc=(to_loc $loc($2))}] } paren_expr: | lparen expr rparen { $2 } +app_arg: + | expr { {paa_label=Unlabeled; paa_expr=$1; paa_loc=to_loc $loc} } + | id_str EQUAL expr { {paa_label=(Labeled $1); paa_expr=$3; paa_loc=to_loc $loc} } + app_expr: - | left_accessor_expr lparen lseparated_list(comma, expr) comma? rparen { Expression.apply ~loc:(to_loc $loc) $1 $3 } + | left_accessor_expr lparen lseparated_list(comma, app_arg) comma? rparen { Expression.apply ~loc:(to_loc $loc) $1 $3 } rcaret_rcaret_op: | lnonempty_list(RCARET) RCARET { (String.init (1 + List.length $1) (fun _ -> '>')) } @@ -456,7 +471,7 @@ special_op: qualified_lid: | modid dot id_str { mkid (List.append $1 [$3]) (to_loc $loc) } - | id_str { (mkid [$1]) (to_loc $loc) } + | id_str %prec EQUAL { (mkid [$1]) (to_loc $loc) } qualified_uid: | lseparated_nonempty_list(dot, type_id_str) %prec DOT { (mkid $1) (to_loc $loc) } @@ -483,9 +498,18 @@ braced_expr: block: | lbrace block_body rbrace { Expression.block ~loc:(to_loc $loc) $2 } +arg_default: + | EQUAL non_stmt_expr { $2 } + +lam_arg: + | pattern arg_default? { LambdaArgument.mk ~loc:(to_loc $loc) $1 $2 } + +lam_args: + | lseparated_nonempty_list(comma, lam_arg) comma? { $1 } + lam_expr: - | FUN lparen patterns? rparen thickarrow expr { Expression.lambda ~loc:(to_loc $loc) (Option.value ~default:[] $3) $6 } - | FUN LIDENT thickarrow expr { Expression.lambda ~loc:(to_loc $loc) [Pattern.var ~loc:(to_loc $loc($2)) (mkstr $loc($2) $2)] $4 } + | FUN lparen lam_args? rparen thickarrow expr { Expression.lambda ~loc:(to_loc $loc) (Option.value ~default:[] $3) $6 } + | FUN LIDENT thickarrow expr { Expression.lambda ~loc:(to_loc $loc) [LambdaArgument.mk ~loc:(to_loc $loc($2)) (Pattern.var ~loc:(to_loc $loc($2)) (mkstr $loc($2) $2)) None] $4 } attribute_argument: | STRING { mkstr $loc $1 } @@ -546,9 +570,9 @@ array_expr: | lbrackrcaret opt_eols lseparated_nonempty_list(comma, expr) comma? rbrack { Expression.array ~loc:(to_loc $loc) $3 } stmt_expr: - | THROW expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) "throw"]) [$2] } - | ASSERT expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) "assert"]) [$2] } - | FAIL expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) "fail"]) [$2] } + | THROW expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) "throw"]) [{paa_label=Unlabeled; paa_expr=$2; paa_loc=(to_loc $loc($2))}] } + | ASSERT expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) "assert"]) [{paa_label=Unlabeled; paa_expr=$2; paa_loc=(to_loc $loc($2))}] } + | FAIL expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) "fail"]) [{paa_label=Unlabeled; paa_expr=$2; paa_loc=(to_loc $loc($2))}] } // allow DASH to cause a shift instead of the usual reduction of the left side for subtraction | RETURN ioption(expr) %prec _below_infix { Expression.return ~loc:(to_loc $loc) $2 } | CONTINUE { Expression.continue ~loc:(to_loc $loc) () } @@ -561,7 +585,7 @@ assign_binop_op: assign_expr: | left_accessor_expr GETS opt_eols expr { Expression.box_assign ~loc:(to_loc $loc) $1 $4 } | id_expr equal expr { Expression.assign ~loc:(to_loc $loc) $1 $3 } - | id_expr assign_binop_op opt_eols expr { Expression.assign ~loc:(to_loc $loc) $1 (Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($2) [$2]) [$1; $4]) } + | id_expr assign_binop_op opt_eols expr { Expression.assign ~loc:(to_loc $loc) $1 (Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($2) [$2]) [{paa_label=Unlabeled; paa_expr=$1; paa_loc=(to_loc $loc($1))}; {paa_label=Unlabeled; paa_expr=$4; paa_loc=(to_loc $loc($4))}]) } | record_set { $1 } | array_set { $1 } @@ -605,7 +629,7 @@ record_get: record_set: | left_accessor_expr dot lid equal expr { Expression.record_set ~loc:(to_loc $loc) $1 $3 $5 } - | left_accessor_expr dot lid assign_binop_op opt_eols expr { Expression.record_set ~loc:(to_loc $loc) $1 $3 (Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($4) [$4]) [Expression.record_get ~loc:(to_loc $loc) $1 $3; $6]) } + | left_accessor_expr dot lid assign_binop_op opt_eols expr { Expression.record_set ~loc:(to_loc $loc) $1 $3 (Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($4) [$4]) [{paa_label=Unlabeled; paa_expr=Expression.record_get ~loc:(to_loc $loc) $1 $3; paa_loc=(to_loc $loc($6))}; {paa_label=Unlabeled; paa_expr=$6; paa_loc=(to_loc $loc($6))}]) } %inline record_field_value: | colon expr {$2} diff --git a/compiler/src/parsing/parsetree.re b/compiler/src/parsing/parsetree.re index 2f6cd7ffca..22cbef0341 100644 --- a/compiler/src/parsing/parsetree.re +++ b/compiler/src/parsing/parsetree.re @@ -25,7 +25,7 @@ type mut_flag = Asttypes.mut_flag = | Mutable | Immutable; type parsed_type_desc = | PTyAny | PTyVar(string) - | PTyArrow(list(parsed_type), parsed_type) + | PTyArrow(list(parsed_type_argument), parsed_type) | PTyTuple(list(parsed_type)) | PTyConstr(loc(Identifier.t), list(parsed_type)) | PTyPoly(list(loc(string)), parsed_type) @@ -34,6 +34,12 @@ and parsed_type = { ptyp_desc: parsed_type_desc, [@sexp_drop_if sexp_locs_disabled] ptyp_loc: Location.t, +} + +and parsed_type_argument = { + ptyp_arg_label: argument_label, + ptyp_arg_type: parsed_type, + ptyp_arg_loc: Location.t, }; /** Type for fields within a record */ @@ -511,8 +517,8 @@ and expression_desc = | PExpReturn(option(expression)) | PExpConstraint(expression, parsed_type) | PExpUse(loc(Identifier.t), use_items) - | PExpLambda(list(pattern), expression) - | PExpApp(expression, list(expression)) + | PExpLambda(list(lambda_argument), expression) + | PExpApp(expression, list(application_argument)) | PExpConstruct(loc(Identifier.t), constructor_expression) | PExpBlock(list(expression)) | PExpBoxAssign(expression, expression) @@ -524,6 +530,21 @@ and constructor_expression = | PExpConstrRecord(list((loc(Identifier.t), expression))) | PExpConstrSingleton +[@deriving (sexp, yojson)] +and lambda_argument = { + pla_label: argument_label, + pla_pattern: pattern, + pla_default: option(expression), + pla_loc: Location.t, +} + +[@deriving (sexp, yojson)] +and application_argument = { + paa_label: argument_label, + paa_expr: expression, + paa_loc: Location.t, +} + /** let-binding form */ [@deriving (sexp, yojson)] diff --git a/compiler/src/parsing/parsetree_iter.re b/compiler/src/parsing/parsetree_iter.re index fe4a3d238f..3cabab112a 100644 --- a/compiler/src/parsing/parsetree_iter.re +++ b/compiler/src/parsing/parsetree_iter.re @@ -302,11 +302,24 @@ and iter_expression = | PUseAll => () }; | PExpLambda(pl, e) => - iter_patterns(hooks, pl); + List.iter( + arg => { + iter_pattern(hooks, arg.pla_pattern); + Option.iter(iter_expression(hooks), arg.pla_default); + iter_location(hooks, arg.pla_loc); + }, + pl, + ); iter_expression(hooks, e); | PExpApp(e, el) => iter_expression(hooks, e); - iter_expressions(hooks, el); + List.iter( + arg => { + iter_expression(hooks, arg.paa_expr); + iter_location(hooks, arg.paa_loc); + }, + el, + ); | PExpConstruct(c, e) => iter_ident(hooks, c); switch (e) { @@ -364,7 +377,13 @@ and iter_type = (hooks, {ptyp_desc: desc, ptyp_loc: loc} as typ) => { | PTyAny => () | PTyVar(v) => () | PTyArrow(args, ret) => - List.iter(iter_type(hooks), args); + List.iter( + arg => { + iter_type(hooks, arg.ptyp_arg_type); + iter_location(hooks, arg.ptyp_arg_loc); + }, + args, + ); iter_type(hooks, ret); | PTyTuple(ts) => List.iter(iter_type(hooks), ts) | PTyConstr(name, ts) => diff --git a/compiler/src/typed/btype.re b/compiler/src/typed/btype.re index 876ccc3ae2..d92f76f4cd 100644 --- a/compiler/src/typed/btype.re +++ b/compiler/src/typed/btype.re @@ -130,7 +130,7 @@ let iter_type_expr = (f, ty) => switch (ty.desc) { | TTyVar(_) => () | TTyArrow(args, ret, _) => - List.iter(f, args); + List.iter(((_, arg)) => f(arg), args); f(ret); | TTyTuple(ts) => List.iter(f, ts) | TTyRecord(ts) => List.iter(((_, t)) => f(t), ts) @@ -276,7 +276,11 @@ let rec copy_type_desc = (~keep_names=false, f) => TTyVar(None); } | TTyArrow(tyl, ret, c) => - TTyArrow(List.map(f, tyl), f(ret), copy_commu(c)) + TTyArrow( + List.map(((l, arg)) => (l, f(arg)), tyl), + f(ret), + copy_commu(c), + ) | TTyTuple(l) => TTyTuple(List.map(f, l)) | TTyRecord(l) => TTyRecord(List.map(((name, arg)) => (name, f(arg)), l)) @@ -406,20 +410,42 @@ let forget_abbrev = (mem, path) => let is_optional = fun - | Optional(_) => true + | Default(_) => true | _ => false; +let label_equal = (l1, l2) => { + switch (l1, l2) { + | (Unlabeled, Unlabeled) => true + | (Labeled({txt: name1}), Labeled({txt: name2})) + | (Default({txt: name1}), Default({txt: name2})) when name1 == name2 => + true + | _ => false + }; +}; + +let same_label_name = (l1, l2) => + switch (l1, l2) { + | (Unlabeled, Unlabeled) => true + | ( + Labeled({txt: name1}) | Default({txt: name1}), + Labeled({txt: name2}) | Default({txt: name2}), + ) + when name1 == name2 => + true + | _ => false + }; + let label_name = fun - | Nolabel => "" - | Labelled(s) - | Optional(s) => s; + | Unlabeled => "" + | Labeled(s) + | Default(s) => s.txt; -let prefixed_label_name = +let qualified_label_name = fun - | Nolabel => "" - | Labelled(s) => "~" ++ s - | Optional(s) => "?" ++ s; + | Unlabeled => "" + | Labeled(s) => s.txt + | Default(s) => "?" ++ s.txt; let rec extract_label_aux = (hd, l) => fun diff --git a/compiler/src/typed/btype.rei b/compiler/src/typed/btype.rei index 823c89dd39..2255adfeb1 100644 --- a/compiler/src/typed/btype.rei +++ b/compiler/src/typed/btype.rei @@ -110,6 +110,21 @@ let memorize_abbrev: let forget_abbrev: (ref(abbrev_memo), Path.t) => unit; /* Remove an abbreviation from the cache */ +/**** Utilities for labels ****/ +let is_optional: argument_label => bool; +let label_equal: (argument_label, argument_label) => bool; +let same_label_name: (argument_label, argument_label) => bool; +let label_name: argument_label => label; +let qualified_label_name: argument_label => label; +let extract_label: + (label, list((argument_label, 'a))) => + ( + argument_label, + 'a, + list((argument_label, 'a)), + list((argument_label, 'a)), + ); + /**** Utilities for backtracking ****/ type snapshot; diff --git a/compiler/src/typed/ctype.re b/compiler/src/typed/ctype.re index 85d45d6937..21a5e5805d 100644 --- a/compiler/src/typed/ctype.re +++ b/compiler/src/typed/ctype.re @@ -415,7 +415,7 @@ let rec generalize_spine = ty => { switch (ty.desc) { | TTyArrow(tyl, ty2, _) => set_level(ty, generic_level); - List.iter(generalize_spine, tyl); + List.iter(((_, ty)) => generalize_spine(ty), tyl); generalize_spine(ty2); | TTyPoly(ty', _) => set_level(ty, generic_level); @@ -555,7 +555,7 @@ let rec generalize_expansive = (env, var_level, visited, ty) => { else generalize_expansive env var_level visited t) variance tyl*/ | TTyArrow(tl, t2, _) => - List.iter(generalize_structure(var_level), tl); + List.iter(((_, ty)) => generalize_structure(var_level, ty), tl); generalize_expansive(env, var_level, visited, t2); | _ => iter_type_expr(generalize_expansive(env, var_level, visited), ty) }; @@ -1981,8 +1981,21 @@ let rec mcomp = (type_pairs, env, t1, t2) => switch (t1'.desc, t2'.desc) { | (TTyVar(_), _) | (_, TTyVar(_)) => () - | (TTyArrow(t1, u1, _), TTyArrow(t2, u2, _)) => - mcomp_list(type_pairs, env, t1, t2); + | (TTyArrow(a1, u1, _), TTyArrow(a2, u2, _)) + when + List.length(a1) == List.length(a2) + && List.for_all2( + ((l1, _), (l2, _)) => + is_optional(l1) == is_optional(l2), + a1, + a2, + ) => + mcomp_list( + type_pairs, + env, + List.map(snd, a1), + List.map(snd, a2), + ); mcomp(type_pairs, env, u1, u2); | (TTyTuple(tl1), TTyTuple(tl2)) => mcomp_list(type_pairs, env, tl1, tl2) @@ -2447,8 +2460,16 @@ and unify3 = (env, t1, t1', t2, t2') => { try( { switch (d1, d2) { - | (TTyArrow(t1, u1, c1), TTyArrow(t2, u2, c2)) => - unify_list(env, t1, t2); + | (TTyArrow(a1, u1, c1), TTyArrow(a2, u2, c2)) + when + List.length(a1) == List.length(a2) + && List.for_all2( + ((l1, _), (l2, _)) => + is_optional(l1) == is_optional(l2), + a1, + a2, + ) => + unify_list(env, List.map(snd, a1), List.map(snd, a2)); unify(env, u1, u2); switch (commu_repr(c1), commu_repr(c2)) { | (TComLink(r), c2) => set_commu(r, c2) @@ -2606,29 +2627,58 @@ let unify = (env, ty1, ty2) => unify_pairs(ref(env), ty1, ty2, []); /**** Special cases of unification ****/ let expand_head_trace = (env, t) => { - let t = expand_head_unif(env, t); - t; + expand_head_unif(env, t); }; -let filter_arrow = (arity, env, t) => { - let t = expand_head_trace(env, t); +type filter_arrow_failure = + | Unification_error(list((type_expr, type_expr))) + | Label_mismatch({ + got: argument_label, + expected: argument_label, + expected_type: type_expr, + }) + | Arity_mismatch + | Not_a_function; + +exception Filter_arrow_failed(filter_arrow_failure); + +let filter_arrow = (env, t, labels) => { + let t = + try(expand_head_trace(env, t)) { + | Unify(types) => raise(Filter_arrow_failed(Unification_error(types))) + }; switch (t.desc) { | TTyVar(_) => - /*Printf.eprintf "filter_arrow: TTyVar\n";*/ let lv = t.level; - let vars = ref([]); - for (i in 1 to arity) { - vars := [newvar2(lv), ...vars^]; - }; + let vars = List.map(_ => newvar2(lv), labels); + let args = List.combine(labels, vars); let t2 = newvar2(lv); - let t' = newty2(lv, TTyArrow(vars^, t2, TComOk)); + let t' = newty2(lv, TTyArrow(args, t2, TComOk)); link_type(t, t'); - (vars^, t2); - | TTyArrow(t1, t2, _) => - /*Printf.eprintf "filter_arrow: TTyArrow\n";*/ - (t1, t2) - | _ => raise(Unify([])) + (vars, t2); + | TTyArrow(a1, t2, _) => + let types = + try( + List.map2( + (l, (l', ty)) => + if (is_optional(l) == is_optional(l')) { + ty; + } else { + raise( + Filter_arrow_failed( + Label_mismatch({got: l, expected: l', expected_type: ty}), + ), + ); + }, + labels, + a1, + ) + ) { + | Invalid_argument(_) => raise(Filter_arrow_failed(Arity_mismatch)) + }; + (types, t2); + | _ => raise(Filter_arrow_failed(Not_a_function)) }; }; @@ -2708,8 +2758,14 @@ let rec moregen = (inst_nongen, type_pairs, env, t1, t2) => | (TTyVar(_), _) when may_instantiate(inst_nongen, t1') => moregen_occur(env, t1'.level, t2); link_type(t1', t2); - | (TTyArrow(t1, u1, _), TTyArrow(t2, u2, _)) => - moregen_list(inst_nongen, type_pairs, env, t1, t2); + | (TTyArrow(a1, u1, _), TTyArrow(a2, u2, _)) => + moregen_list( + inst_nongen, + type_pairs, + env, + List.map(snd, a1), + List.map(snd, a2), + ); moregen(inst_nongen, type_pairs, env, u1, u2); | (TTyTuple(tl1), TTyTuple(tl2)) => moregen_list(inst_nongen, type_pairs, env, tl1, tl2) @@ -2928,8 +2984,15 @@ let rec eqtype = (rename, type_pairs, subst, env, t1, t2) => }; subst := [(t1', t2'), ...subst^]; } - | (TTyArrow(t1, u1, _), TTyArrow(t2, u2, _)) => - eqtype_list(rename, type_pairs, subst, env, t1, t2); + | (TTyArrow(a1, u1, _), TTyArrow(a2, u2, _)) => + eqtype_list( + rename, + type_pairs, + subst, + env, + List.map(snd, a1), + List.map(snd, a2), + ); eqtype(rename, type_pairs, subst, env, u1, u2); | (TTyTuple(tl1), TTyTuple(tl2)) => eqtype_list(rename, type_pairs, subst, env, tl1, tl2) diff --git a/compiler/src/typed/ctype.rei b/compiler/src/typed/ctype.rei index 9be76ffdf3..6cbcf71cfd 100644 --- a/compiler/src/typed/ctype.rei +++ b/compiler/src/typed/ctype.rei @@ -159,7 +159,21 @@ let unify_var: (Env.t, type_expr, type_expr) => unit; is a variable. */ let with_passive_variants: ('a => 'b, 'a) => 'b; /* Call [f] in passive_variants mode, for exhaustiveness check. */ -let filter_arrow: (int, Env.t, type_expr) => (list(type_expr), type_expr); + +type filter_arrow_failure = + | Unification_error(list((type_expr, type_expr))) + | Label_mismatch({ + got: argument_label, + expected: argument_label, + expected_type: type_expr, + }) + | Arity_mismatch + | Not_a_function; + +exception Filter_arrow_failed(filter_arrow_failure); + +let filter_arrow: + (Env.t, type_expr, list(argument_label)) => (list(type_expr), type_expr); /* A special case of unification (with l:'a -> 'b). */ let occur_in: (Env.t, type_expr, type_expr) => bool; let deep_occur: (type_expr, type_expr) => bool; diff --git a/compiler/src/typed/env.re b/compiler/src/typed/env.re index 966f22ffda..8cf22fa759 100644 --- a/compiler/src/typed/env.re +++ b/compiler/src/typed/env.re @@ -1684,7 +1684,13 @@ and components_of_module_maker = ((env, sub, path, mty)) => switch (desc.cstr_args) { | [] => desc.cstr_res | args => - Btype.newgenty(TTyArrow(args, desc.cstr_res, TComOk)) + Btype.newgenty( + TTyArrow( + List.map(arg => (Unlabeled, arg), args), + desc.cstr_res, + TComOk, + ), + ) }; let val_type = switch (desc.cstr_existentials) { @@ -1748,7 +1754,14 @@ and components_of_module_maker = ((env, sub, path, mty)) => let val_type = switch (desc.cstr_args) { | [] => desc.cstr_res - | args => Btype.newgenty(TTyArrow(args, desc.cstr_res, TComOk)) + | args => + Btype.newgenty( + TTyArrow( + List.map(arg => (Unlabeled, arg), args), + desc.cstr_res, + TComOk, + ), + ) }; let val_type = switch (desc.cstr_existentials) { diff --git a/compiler/src/typed/oprint.re b/compiler/src/typed/oprint.re index bd5136168a..16df05f87c 100644 --- a/compiler/src/typed/oprint.re +++ b/compiler/src/typed/oprint.re @@ -353,14 +353,18 @@ let rec print_out_type = ppf => and print_out_type_1 = ppf => fun - | Otyp_arrow(ty1, ty2) => { - let args_length = List.length(ty1); + | Otyp_arrow(al, ty2) => { + let parens = + switch (al) { + | [("", _)] => false + | _ => true + }; pp_open_box(ppf, 1); - if (args_length != 1) { + if (parens) { pp_print_char(ppf, '('); }; - fprintf(ppf, "@[<0>%a@]", print_typlist(print_out_type_2, ","), ty1); - if (args_length != 1) { + fprintf(ppf, "@[<0>%a@]", print_argtyplist(print_out_type_2, ","), al); + if (parens) { pp_print_char(ppf, ')'); }; pp_print_string(ppf, " ->"); @@ -519,6 +523,26 @@ and print_row_field = (ppf, (l, opt_amp, tyl)) => { tyl, ); } +and print_argtyplist = (print_elem, sep, ppf) => + fun + | [] => () + | [(l, ty)] => { + if (l != "") { + pp_print_string(ppf, l); + pp_print_string(ppf, ": "); + }; + print_elem(ppf, ty); + } + | [(l, ty), ...al] => { + if (l != "") { + pp_print_string(ppf, l); + pp_print_string(ppf, ": "); + }; + print_elem(ppf, ty); + pp_print_string(ppf, sep); + pp_print_space(ppf, ()); + print_argtyplist(print_elem, sep, ppf, al); + } and print_typlist = (print_elem, sep, ppf) => fun | [] => () diff --git a/compiler/src/typed/outcometree.re b/compiler/src/typed/outcometree.re index 06fb71e7f2..3e9cc6704b 100644 --- a/compiler/src/typed/outcometree.re +++ b/compiler/src/typed/outcometree.re @@ -54,7 +54,7 @@ type out_type = | Otyp_abstract | Otyp_open | Otyp_alias(out_type, string) - | Otyp_arrow(list(out_type), out_type) + | Otyp_arrow(list((string, out_type)), out_type) | Otyp_class(bool, out_ident, list(out_type)) | Otyp_constr(out_ident, list(out_type)) | Otyp_manifest(out_type, out_type) diff --git a/compiler/src/typed/printtyp.re b/compiler/src/typed/printtyp.re index dc97631b35..5df5f441b8 100644 --- a/compiler/src/typed/printtyp.re +++ b/compiler/src/typed/printtyp.re @@ -152,16 +152,20 @@ let rec raw_type = (ppf, ty) => { ); }; } +and raw_argtype = (ppf, (l, ty)) => { + fprintf(ppf, "@[<1>%s: %a@]", qualified_label_name(l), raw_type, ty); +} and raw_type_list = tl => raw_list(raw_type, tl) +and raw_argtype_list = al => raw_list(raw_argtype, al) and raw_type_desc = ppf => fun | TTyVar(name) => fprintf(ppf, "TTyVar %a", print_name, name) - | TTyArrow(t1, t2, c) => + | TTyArrow(a1, t2, c) => fprintf( ppf, "@[TTyArrow(@,%a,@,%a,@,%s)@]", - raw_type_list, - t1, + raw_argtype_list, + a1, raw_type, t2, safe_commu_repr([], c), @@ -581,8 +585,8 @@ let rec mark_loops_rec = (visited, ty) => { let visited = [px, ...visited]; switch (ty.desc) { | TTyVar(_) => add_named_var(ty) - | TTyArrow(ty1, ty2, _) => - List.iter(mark_loops_rec(visited), ty1); + | TTyArrow(a1, ty2, _) => + List.iter(((_, t)) => mark_loops_rec(visited, t), a1); mark_loops_rec(visited, ty2); | TTyTuple(tyl) => List.iter(mark_loops_rec(visited), tyl) | TTyRecord(tyl) => @@ -659,12 +663,12 @@ let rec tree_of_typexp = (sch, ty) => { new_name; }; Otyp_var(non_gen, name_of_type(name_gen, ty)); - | TTyArrow(ty1, ty2, _) => - let pr_arrow = (ty1, ty2) => { - let t1 = tree_of_typlist(sch, ty1); - Otyp_arrow(t1, tree_of_typexp(sch, ty2)); + | TTyArrow(a1, ty2, _) => + let pr_arrow = (a1, ty2) => { + let a1 = tree_of_argtyplist(sch, a1); + Otyp_arrow(a1, tree_of_typexp(sch, ty2)); }; - pr_arrow(ty1, ty2); + pr_arrow(a1, ty2); | TTyTuple(tyl) => Otyp_tuple(tree_of_typlist(sch, tyl)) | TTyRecord(tyl) => Otyp_record( @@ -719,6 +723,23 @@ let rec tree_of_typexp = (sch, ty) => { } and tree_of_typlist = (sch, tyl) => List.map(tree_of_typexp(sch), tyl) +and tree_of_argtyplist = (sch, al) => + List.map( + ((l, ty)) => { + let ty = + switch (l) { + | Default(_) => + switch (ty.desc) { + | TTyConstr(_, [ty], _) => ty + | _ => + failwith("Impossible: optional argument with non-option type") + } + | _ => ty + }; + (qualified_label_name(l), tree_of_typexp(sch, ty)); + }, + al, + ) and is_non_gen = (sch, ty) => sch && is_Tvar(ty) && ty.level != generic_level diff --git a/compiler/src/typed/translprim.re b/compiler/src/typed/translprim.re index c4c44abcfb..0d2808409a 100644 --- a/compiler/src/typed/translprim.re +++ b/compiler/src/typed/translprim.re @@ -1468,6 +1468,13 @@ let transl_prim = (env, desc) => { let disable_gc = [(Location.mknoloc("disableGC"), [])]; + let lambda_arg = pat => { + pla_label: Unlabeled, + pla_pattern: pat, + pla_default: None, + pla_loc: Location.dummy_loc, + }; + // `attrs` are attributes which should be applied to the `let` which gets implicitly generated. // // Specifically, consider: @@ -1593,7 +1600,7 @@ let transl_prim = (env, desc) => { Expression.lambda( ~loc, ~attributes, - [pat_a], + [lambda_arg(pat_a)], Expression.prim1(~loc, p, id_a), ), Typecore.prim1_type(p), @@ -1619,7 +1626,7 @@ let transl_prim = (env, desc) => { Expression.lambda( ~loc, ~attributes, - [pat_a, pat_b], + [lambda_arg(pat_a), lambda_arg(pat_b)], Expression.prim2(~loc, p, id_a, id_b), ), Typecore.prim2_type(p), @@ -1639,7 +1646,7 @@ let transl_prim = (env, desc) => { Expression.lambda( ~loc, ~attributes, - [pat_a, pat_b, pat_c], + [lambda_arg(pat_a), lambda_arg(pat_b), lambda_arg(pat_c)], Expression.primn(~loc, p, [id_a, id_b, id_c]), ), Typecore.primn_type(p), diff --git a/compiler/src/typed/translsig.re b/compiler/src/typed/translsig.re index 8f32e457f0..7c61d7bd33 100644 --- a/compiler/src/typed/translsig.re +++ b/compiler/src/typed/translsig.re @@ -17,7 +17,7 @@ let rec collect_type_vars = typ => Tbl.add(typ.id, ref([typ]), used_type_variables^) } | TTyArrow(ty_args, ty_res, _) => - List.iter(collect_type_vars, ty_args); + List.iter(((_, arg)) => collect_type_vars(arg), ty_args); collect_type_vars(ty_res); | TTyTuple(ty_args) => List.iter(collect_type_vars, ty_args) | TTyRecord(ty_args) => @@ -46,7 +46,11 @@ let link_type_vars = ty => { | Not_found => ty } | TTyArrow(tyl, ret, c) => - TTyArrow(List.map(link_types, tyl), link_types(ret), c) + TTyArrow( + List.map(((l, arg)) => (l, link_types(arg)), tyl), + link_types(ret), + c, + ) | TTyTuple(l) => TTyTuple(List.map(link_types, l)) | TTyRecord(l) => TTyRecord(List.map(((name, arg)) => (name, link_types(arg)), l)) diff --git a/compiler/src/typed/type_utils.re b/compiler/src/typed/type_utils.re index ca0b3d79a4..d6d6f4f8e7 100644 --- a/compiler/src/typed/type_utils.re +++ b/compiler/src/typed/type_utils.re @@ -24,7 +24,7 @@ let rec get_fn_allocation_type = (env, ty) => { | TTySubst(linked) | TTyLink(linked) => get_fn_allocation_type(env, linked) | TTyArrow(args, ret, _) => ( - List.map(get_allocation_type(env), args), + List.map(((_, arg)) => get_allocation_type(env, arg), args), get_allocation_type(env, ret), ) | TTyConstr(path, args, _) => diff --git a/compiler/src/typed/typecore.re b/compiler/src/typed/typecore.re index 62ea504b28..a99d4df859 100644 --- a/compiler/src/typed/typecore.re +++ b/compiler/src/typed/typecore.re @@ -11,7 +11,7 @@ open Typepat; open Disambiguation; type error = - | Arity_mismatch(type_expr, int) + | Arity_mismatch(type_expr, option(type_forcing_context)) | Polymorphic_label(Identifier.t) | Constructor_arity_mismatch(Identifier.t, int, int) | Label_mismatch(Identifier.t, list((type_expr, type_expr))) @@ -24,6 +24,9 @@ type error = option(type_forcing_context), ) | Apply_non_function(type_expr) + | Apply_too_many_arguments(type_expr, list((argument_label, type_expr))) + | Apply_too_few_arguments(list((argument_label, type_expr))) + | Apply_unknown_label(string, list(string)) | Label_multiply_defined(string) | Label_missing(list(Ident.t)) | Label_not_mutable(Identifier.t) @@ -55,7 +58,13 @@ type error = list((type_expr, type_expr)), bool, ) - | Too_many_arguments(bool, type_expr, option(type_forcing_context)) + | Not_a_function(type_expr, option(type_forcing_context)) + | Function_label_mismatch({ + got: argument_label, + expected: argument_label, + expected_type: type_expr, + explanation: option(type_forcing_context), + }) | Scoping_let_module(string, type_expr) | Masked_instance_variable(Identifier.t) | Not_a_variant_type(Identifier.t) @@ -98,6 +107,9 @@ let grain_type_of_wasm_prim_type = | Wasm_float64 => Builtin_types.type_wasmf64 | Grain_bool => Builtin_types.type_bool; +let prim_type = (args, ret) => + newgenty(TTyArrow(List.map(ty => (Unlabeled, ty), args), ret, TComOk)); + let prim0_type = fun | AllocateInt32 @@ -107,9 +119,8 @@ let prim0_type = | AllocateFloat32 | AllocateFloat64 | AllocateRational - | WasmMemorySize => - newgenty(TTyArrow([], Builtin_types.type_wasmi32, TComOk)) - | Unreachable => newgenty(TTyArrow([], newgenvar(~name="a", ()), TComOk)); + | WasmMemorySize => prim_type([], Builtin_types.type_wasmi32) + | Unreachable => prim_type([], newgenvar(~name="a", ())); let prim1_type = fun @@ -121,386 +132,188 @@ let prim1_type = | LoadAdtVariant | StringSize | BytesSize => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_wasmi32) | NewInt32 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_wasmi32) | NewInt64 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi64], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi64], Builtin_types.type_wasmi32) | NewUint32 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_wasmi32) | NewUint64 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi64], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi64], Builtin_types.type_wasmi32) | NewFloat32 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmf32], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmf32], Builtin_types.type_wasmi32) | NewFloat64 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmf64], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmf64], Builtin_types.type_wasmi32) | BuiltinId => - newgenty( - TTyArrow( - [Builtin_types.type_string], - Builtin_types.type_number, - TComOk, - ), - ) + prim_type([Builtin_types.type_string], Builtin_types.type_number) | TagSimpleNumber => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_number, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_number) | UntagSimpleNumber => - newgenty( - TTyArrow( - [Builtin_types.type_number], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_number], Builtin_types.type_wasmi32) | TagChar => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_char, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_char) | UntagChar => - newgenty( - TTyArrow( - [Builtin_types.type_char], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_char], Builtin_types.type_wasmi32) | TagInt8 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_int8, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_int8) | UntagInt8 => - newgenty( - TTyArrow( - [Builtin_types.type_int8], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_int8], Builtin_types.type_wasmi32) | TagInt16 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_int16, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_int16) | UntagInt16 => - newgenty( - TTyArrow( - [Builtin_types.type_int16], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_int16], Builtin_types.type_wasmi32) | TagUint8 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_uint8, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_uint8) | UntagUint8 => - newgenty( - TTyArrow( - [Builtin_types.type_uint8], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([Builtin_types.type_uint8], Builtin_types.type_wasmi32) | TagUint16 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_uint16, - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_uint16) | UntagUint16 => - newgenty( - TTyArrow( - [Builtin_types.type_uint16], - Builtin_types.type_wasmi32, - TComOk, - ), - ) - | Not => - newgenty( - TTyArrow([Builtin_types.type_bool], Builtin_types.type_bool, TComOk), - ) + prim_type([Builtin_types.type_uint16], Builtin_types.type_wasmi32) + | Not => prim_type([Builtin_types.type_bool], Builtin_types.type_bool) | Box | BoxBind => { let var = newgenvar(~name="a", ()); - newgenty(TTyArrow([var], Builtin_types.type_box(var), TComOk)); + prim_type([var], Builtin_types.type_box(var)); } | Unbox | UnboxBind => { let var = newgenvar(~name="a", ()); - newgenty(TTyArrow([Builtin_types.type_box(var)], var, TComOk)); + prim_type([Builtin_types.type_box(var)], var); } | Ignore => { let var = newgenvar(~name="a", ()); - newgenty(TTyArrow([var], Builtin_types.type_void, TComOk)); + prim_type([var], Builtin_types.type_void); } | ArrayLength => { let var = newgenvar(~name="a", ()); - newgenty( - TTyArrow( - [Builtin_types.type_array(var)], - Builtin_types.type_number, - TComOk, - ), - ); + prim_type([Builtin_types.type_array(var)], Builtin_types.type_number); } - | Assert => - newgenty( - TTyArrow([Builtin_types.type_bool], Builtin_types.type_void, TComOk), - ) + | Assert => prim_type([Builtin_types.type_bool], Builtin_types.type_void) | Throw => - newgenty( - TTyArrow( - [Builtin_types.type_exception], - newgenvar(~name="a", ()), - TComOk, - ), - ) + prim_type([Builtin_types.type_exception], newgenvar(~name="a", ())) | WasmFromGrain => - newgenty( - TTyArrow( - [newgenvar(~name="a", ())], - Builtin_types.type_wasmi32, - TComOk, - ), - ) + prim_type([newgenvar(~name="a", ())], Builtin_types.type_wasmi32) | WasmToGrain => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - newgenvar(~name="a", ()), - TComOk, - ), - ) + prim_type([Builtin_types.type_wasmi32], newgenvar(~name="a", ())) | WasmUnaryI32({arg_type, ret_type}) | WasmUnaryI64({arg_type, ret_type}) | WasmUnaryF32({arg_type, ret_type}) | WasmUnaryF64({arg_type, ret_type}) => - newgenty( - TTyArrow( - [grain_type_of_wasm_prim_type(arg_type)], - grain_type_of_wasm_prim_type(ret_type), - TComOk, - ), + prim_type( + [grain_type_of_wasm_prim_type(arg_type)], + grain_type_of_wasm_prim_type(ret_type), ) | WasmMemoryGrow => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32], - Builtin_types.type_wasmi32, - TComOk, - ), - ); + prim_type([Builtin_types.type_wasmi32], Builtin_types.type_wasmi32); let prim2_type = fun | NewRational => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], - Builtin_types.type_wasmi32, - TComOk, - ), + prim_type( + [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], + Builtin_types.type_wasmi32, ) | And | Or => - newgenty( - TTyArrow( - [Builtin_types.type_bool, Builtin_types.type_bool], - Builtin_types.type_bool, - TComOk, - ), + prim_type( + [Builtin_types.type_bool, Builtin_types.type_bool], + Builtin_types.type_bool, ) | Is | Eq => { let v = newgenvar(~name="a", ()); - newgenty(TTyArrow([v, v], Builtin_types.type_bool, TComOk)); + prim_type([v, v], Builtin_types.type_bool); } | WasmBinaryI32({arg_types: (arg1_type, arg2_type), ret_type}) | WasmBinaryI64({arg_types: (arg1_type, arg2_type), ret_type}) | WasmBinaryF32({arg_types: (arg1_type, arg2_type), ret_type}) | WasmBinaryF64({arg_types: (arg1_type, arg2_type), ret_type}) => - newgenty( - TTyArrow( - [ - grain_type_of_wasm_prim_type(arg1_type), - grain_type_of_wasm_prim_type(arg2_type), - ], - grain_type_of_wasm_prim_type(ret_type), - TComOk, - ), + prim_type( + [ + grain_type_of_wasm_prim_type(arg1_type), + grain_type_of_wasm_prim_type(arg2_type), + ], + grain_type_of_wasm_prim_type(ret_type), ) | WasmLoadI32(_) => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], - Builtin_types.type_wasmi32, - TComOk, - ), + prim_type( + [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], + Builtin_types.type_wasmi32, ) | WasmLoadI64(_) => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], - Builtin_types.type_wasmi64, - TComOk, - ), + prim_type( + [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], + Builtin_types.type_wasmi64, ) | WasmLoadF32 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], - Builtin_types.type_wasmf32, - TComOk, - ), + prim_type( + [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], + Builtin_types.type_wasmf32, ) | WasmLoadF64 => - newgenty( - TTyArrow( - [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], - Builtin_types.type_wasmf64, - TComOk, - ), + prim_type( + [Builtin_types.type_wasmi32, Builtin_types.type_wasmi32], + Builtin_types.type_wasmf64, ); let primn_type = fun | WasmStoreI32(_) => - newgenty( - TTyArrow( - [ - Builtin_types.type_wasmi32, - Builtin_types.type_wasmi32, - Builtin_types.type_wasmi32, - ], - Builtin_types.type_void, - TComOk, - ), + prim_type( + [ + Builtin_types.type_wasmi32, + Builtin_types.type_wasmi32, + Builtin_types.type_wasmi32, + ], + Builtin_types.type_void, ) | WasmStoreI64(_) => - newgenty( - TTyArrow( - [ - Builtin_types.type_wasmi32, - Builtin_types.type_wasmi64, - Builtin_types.type_wasmi32, - ], - Builtin_types.type_void, - TComOk, - ), + prim_type( + [ + Builtin_types.type_wasmi32, + Builtin_types.type_wasmi64, + Builtin_types.type_wasmi32, + ], + Builtin_types.type_void, ) | WasmStoreF32 => - newgenty( - TTyArrow( - [ - Builtin_types.type_wasmi32, - Builtin_types.type_wasmf32, - Builtin_types.type_wasmi32, - ], - Builtin_types.type_void, - TComOk, - ), + prim_type( + [ + Builtin_types.type_wasmi32, + Builtin_types.type_wasmf32, + Builtin_types.type_wasmi32, + ], + Builtin_types.type_void, ) | WasmStoreF64 => - newgenty( - TTyArrow( - [ - Builtin_types.type_wasmi32, - Builtin_types.type_wasmf64, - Builtin_types.type_wasmi32, - ], - Builtin_types.type_void, - TComOk, - ), + prim_type( + [ + Builtin_types.type_wasmi32, + Builtin_types.type_wasmf64, + Builtin_types.type_wasmi32, + ], + Builtin_types.type_void, ) | WasmMemoryCopy | WasmMemoryFill => - newgenty( - TTyArrow( - [ - Builtin_types.type_wasmi32, - Builtin_types.type_wasmi32, - Builtin_types.type_wasmi32, - ], - Builtin_types.type_void, - TComOk, - ), + prim_type( + [ + Builtin_types.type_wasmi32, + Builtin_types.type_wasmi32, + Builtin_types.type_wasmi32, + ], + Builtin_types.type_void, ) | WasmMemoryCompare => - newgenty( - TTyArrow( - [ - Builtin_types.type_wasmi32, - Builtin_types.type_wasmi32, - Builtin_types.type_wasmi32, - ], + prim_type( + [ Builtin_types.type_wasmi32, - TComOk, - ), + Builtin_types.type_wasmi32, + Builtin_types.type_wasmi32, + ], + Builtin_types.type_wasmi32, ); let maybe_add_pattern_variables_ghost = (loc_let, env, pv) => @@ -540,11 +353,6 @@ let constant: let constant_or_raise = Checkertypes.constant_or_raise; -/* Specific version of type_option, using newty rather than newgenty */ - -/*let type_option ty = - newty (TTyConstr(Predef.path_option,[ty], ref TMemNil))*/ - let mkexp = (exp_desc, exp_type, exp_loc, exp_env, exp_attributes) => { exp_desc, exp_type, @@ -554,6 +362,50 @@ let mkexp = (exp_desc, exp_type, exp_loc, exp_env, exp_attributes) => { exp_attributes, }; +/* Specific version of type_option, using newty rather than newgenty */ + +let type_option = ty => + newty(TTyConstr(Builtin_types.path_option, [ty], ref(TMemNil))); + +let option_some = (env, texp) => { + let csome = + Env.find_constructor(Path.PIdent(Builtin_types.ident_some_cstr), env); + mkexp( + TExpConstruct( + mknoloc(Identifier.IdentName(mknoloc("Some"))), + csome, + TExpConstrTuple([texp]), + ), + type_option(texp.exp_type), + texp.exp_loc, + texp.exp_env, + [], + ); +}; + +let option_none = (env, ty, loc) => { + let cnone = + Env.find_constructor(Path.PIdent(Builtin_types.ident_none_cstr), env); + mkexp( + TExpConstruct( + mknoloc(Identifier.IdentName(mknoloc("None"))), + cnone, + TExpConstrTuple([]), + ), + type_option(ty), + loc, + env, + [], + ); +}; + +let extract_option_type = (env, ty) => { + switch (expand_head(env, ty).desc) { + | TTyConstr(path, [ty], _) when Path.same(path, Builtin_types.path_option) => ty + | _ => failwith("Impossible: option type was not an option") + }; +}; + /* Typing of patterns */ /* unification inside type_pat*/ @@ -627,7 +479,7 @@ let rec approx_type = (env, sty) => | PTyArrow(args, ret) => newty( TTyArrow( - List.map(x => newvar(), args), + List.map(x => (x.ptyp_arg_label, newvar()), args), approx_type(env, ret), TComOk, ), @@ -656,7 +508,11 @@ let rec type_approx = (env, sexp: Parsetree.expression) => | PExpWhile(_, e) => type_approx(env, e) | PExpLambda(args, e) => newty( - TTyArrow(List.map(x => newvar(), args), type_approx(env, e), TComOk), + TTyArrow( + List.map(x => (x.pla_label, newvar()), args), + type_approx(env, e), + TComOk, + ), ) | PExpBlock([_, ..._] as es) => type_approx(env, last(es)) | _ => newvar() @@ -1146,6 +1002,85 @@ and type_expect_ = }); | PExpLambda(args, body) => open Ast_helper; + let gen_opt = label => { + let label = + switch (label) { + | Unlabeled => failwith("Impossible: default argument with no label") + | Labeled({txt: name}) + | Default({txt: name}) => name + }; + "$default_option_" ++ label; + }; + let (args, labels, prelude) = + List.fold_right( + (arg, (args, labels, prelude)) => { + switch (arg.pla_default) { + | Some(default) => + let default_value_name = mknoloc("$default_value"); + let default_loc = default.pexp_loc; + let scases = [ + MatchBranch.mk( + Pattern.construct( + ~loc=default_loc, + mknoloc(Identifier.IdentName(mknoloc("Some"))), + PPatConstrTuple([ + Pattern.var(~loc=default_loc, default_value_name), + ]), + ), + Expression.ident( + ~loc=default_loc, + mknoloc(Identifier.IdentName(default_value_name)), + ), + None, + ), + MatchBranch.mk( + Pattern.construct( + ~loc=default_loc, + mknoloc(Identifier.IdentName(mknoloc("None"))), + PPatConstrTuple([]), + ), + default, + None, + ), + ]; + let sloc = { + Location.loc_start: arg.pla_pattern.ppat_loc.Location.loc_start, + loc_end: default_loc.Location.loc_end, + loc_ghost: true, + }; + let opt_name = mknoloc(gen_opt(arg.pla_label)); + let smatch = + Expression.match( + ~loc=sloc, + Expression.ident( + ~loc=sloc, + mknoloc(Identifier.IdentName(opt_name)), + ), + scases, + ); + let pat = Pattern.var(~loc=sloc, opt_name); + let prelude_expr = + Expression.let_( + ~loc=sloc, + Nonrecursive, + Immutable, + [ValueBinding.mk(arg.pla_pattern, smatch)], + ); + ( + [pat, ...args], + [arg.pla_label, ...labels], + [prelude_expr, ...prelude], + ); + | None => ( + [arg.pla_pattern, ...args], + [arg.pla_label, ...labels], + prelude, + ) + } + }, + args, + ([], [], []), + ); let pat = switch (args) { | [] => @@ -1156,13 +1091,18 @@ and type_expect_ = ) | args => Pattern.tuple(args) }; + let body = + switch (prelude) { + | [] => body + | _ => Expression.block(~loc=body.pexp_loc, prelude @ [body]) + }; type_function( ~in_function?, loc, attributes, env, ty_expected_explained, - (), + labels, [MatchBranch.mk(pat, body, None)], ); | PExpApp(func, args) => @@ -1188,11 +1128,12 @@ and type_expect_ = end_def(); /*lower_args [] ty;*/ begin_def(); - let (args, ty_res) = type_application(~in_function?, env, funct, args); + let (label_order, args, ty_res) = + type_application(~in_function?, ~loc, env, funct, args); end_def(); unify_var(env, newvar(), funct.exp_type); rue({ - exp_desc: TExpApp(funct, args), + exp_desc: TExpApp(funct, label_order, args), exp_loc: loc, exp_extra: [], exp_attributes: attributes, @@ -1246,7 +1187,7 @@ and type_expect_ = }); | PExpPrim1(p1, sarg) => let (argtypes, rettype) = - filter_arrow(1, env, instance(env, prim1_type(p1))); + filter_arrow(env, instance(env, prim1_type(p1)), [Unlabeled]); let argtype = switch (argtypes) { | [arg] => arg @@ -1263,7 +1204,11 @@ and type_expect_ = }); | PExpPrim2(p2, sarg1, sarg2) => let (argtypes, rettype) = - filter_arrow(2, env, instance(env, prim2_type(p2))); + filter_arrow( + env, + instance(env, prim2_type(p2)), + [Unlabeled, Unlabeled], + ); let (arg1type, arg2type) = switch (argtypes) { | [arg1, arg2] => (arg1, arg2) @@ -1281,7 +1226,11 @@ and type_expect_ = }); | PExpPrimN(p, sargs) => let (argtypes, rettype) = - filter_arrow(3, env, instance(env, primn_type(p))); + filter_arrow( + env, + instance(env, primn_type(p)), + List.map(_ => Unlabeled, sargs), + ); let args = List.map2( (sarg, argtype) => type_expect(env, sarg, mk_expected(argtype)), @@ -1502,7 +1451,7 @@ and type_expect_ = end_def(); generalize_structure(ty); let (arg, ty') = ( - List.hd @@ type_arguments(env, [sarg], [ty], [instance(env, ty)]), + type_argument(env, sarg, ty, instance(env, ty)), instance(env, ty), ); rue({ @@ -1573,7 +1522,6 @@ and type_expect_ = and type_function = (~in_function=?, loc, attrs, env, ty_expected_explained, l, caselist) => { let {ty: ty_expected, explanation} = ty_expected_explained; - /*Format.eprintf "@[type_function: expected: %a@]@." Printtyp.raw_type_expr ty_expected;*/ let (loc_fun, ty_fun) = (loc, instance(env, ty_expected)); let separate = @@ -1581,59 +1529,33 @@ and type_function = if (separate) { begin_def(); }; - let rec arity = caselist => - switch (caselist) { - | [] => failwith("Impossible: type_function: empty lambda") - | [{pmb_pat: {ppat_desc: PPatConstraint(p, _)}, _} as mb] => - arity([{...mb, pmb_pat: p}]) - | [{pmb_pat: {ppat_desc: PPatTuple(args)}, _}] => List.length(args) - // TODO(#1507): Reduce the number of hard-coded cases - | [ - { - pmb_pat: { - ppat_desc: PPatConstruct({txt: ident, _}, PPatConstrTuple([])), - _, - }, - _, - }, - ] - when Identifier.equal(ident, Identifier.IdentName(mknoloc("()"))) => 0 - | _ => failwith("Impossible: type_function: impossible caselist") - }; - let arity = arity(caselist); let exp_inst = instance(env, ty_expected); - /*Format.eprintf "@[type_function: pre: %a@]@." Printtyp.raw_type_expr exp_inst;*/ - let (ty_arg, ty_res) = - try(filter_arrow(arity, env, exp_inst)) { - | Unify(_) => - raise( - Error( - loc_fun, - env, - Too_many_arguments(in_function != None, ty_fun, explanation), - ), - ) + let (ty_args, ty_res) = + try(filter_arrow(env, exp_inst, l)) { + | Filter_arrow_failed(err) => + let err = + switch (err) { + | Unification_error(unif_err) => Expr_type_clash(unif_err, None) + | Label_mismatch({got, expected, expected_type}) => + Function_label_mismatch({got, expected, expected_type, explanation}) + | Arity_mismatch => Arity_mismatch(ty_fun, explanation) + | Not_a_function => Not_a_function(ty_fun, explanation) + }; + raise(Error(loc_fun, env, err)); }; - - /*let rec fmt_args ppf = function - | [] -> Format.fprintf ppf ")" - | a::tl -> - Format.fprintf ppf "%a, %a" Printtyp.raw_type_expr a fmt_args tl in - Format.eprintf "@[type_function: %i@ (%a -> %a@]@." (get_current_level()) - fmt_args (ty_arg) Printtyp.raw_type_expr ty_res;*/ if (separate) { end_def(); - List.iter(generalize_structure, ty_arg); + List.iter(generalize_structure, ty_args); generalize_structure(ty_res); }; let normalized_arg_type = - switch (ty_arg) { + switch (ty_args) { | [] => Builtin_types.type_void - | _ => newty(TTyTuple(ty_arg)) + | _ => newty(TTyTuple(ty_args)) }; let (cases, partial) = type_cases( - ~in_function=(loc_fun, ty_arg, ty_res), + ~in_function=(loc_fun, ty_args, ty_res), env, normalized_arg_type, ty_res, @@ -1641,77 +1563,51 @@ and type_function = loc, caselist, ); - // TODO: Decide if this should be added to TExpLambda - /*let param = name_pattern "param" cases in*/ re({ exp_desc: TExpLambda(cases, partial), exp_loc: loc, exp_extra: [], exp_attributes: attrs, - exp_type: instance(env, newgenty(TTyArrow(ty_arg, ty_res, TComOk))), + exp_type: + instance( + env, + newgenty(TTyArrow(List.combine(l, ty_args), ty_res, TComOk)), + ), exp_env: env, }); } -and type_arguments = - (~in_function=?, ~recarg=?, env, sargs, tys_expected', tys_expected) => +and type_argument = + (~in_function=?, ~recarg=?, env, sarg, ty_expected', ty_expected) => { /* ty_expected' may be generic */ - /* Note (Philip): I think the heavy lifting of this function - was there to support optional arguments (which we currently don't). */ - List.map2( - (sarg, (targ', targ)) => { - let texp = - type_expect(~in_function?, ~recarg?, env, sarg, mk_expected(targ')); - unify_exp(env, texp, targ); - texp; - }, - sargs, - List.combine(tys_expected', tys_expected), - ) + let texp = + type_expect( + ~in_function?, + ~recarg?, + env, + sarg, + mk_expected(ty_expected'), + ); + unify_exp(env, texp, ty_expected); + texp; +} -and type_application = (~in_function=?, env, funct, args) => { +and type_application = (~in_function=?, ~loc, env, funct, sargs) => { /* funct.exp_type may be generic */ - /*** Arguments, return value */ let ty_fun = expand_head(env, funct.exp_type); - let (ty_args, ty_ret, ty_level) = + let (ty_args, ty_ret) = switch (ty_fun.desc) { | TTyVar(_) => - let t_args = List.map(x => newvar(), args) + let t_args = List.map(arg => (arg.paa_label, newvar()), sargs) and t_ret = newvar(); - /*let not_identity = function - | TExpIdent(_,_,{val_kind=TValPrim - {Primitive.prim_name="%identity"}}) -> - false - | _ -> true - in - List.iter2 (fun arg t_arg -> - if ty_fun.level >= t_arg.level && not_identity funct.exp_desc then - Location.prerr_warning arg.pexp_loc Warnings.Unused_argument - ) args t_args;*/ unify( env, ty_fun, newty(TTyArrow(t_args, t_ret, TComLink(ref(TComUnknown)))), ); - (t_args, t_ret, ty_fun.level); - | TTyArrow(t_args, t_ret, _) - when List.length(t_args) == List.length(args) => ( - t_args, - t_ret, - ty_fun.level, - ) - | TTyArrow(t_args, t_ret, _) => - raise( - Error( - funct.exp_loc, - env, - Arity_mismatch( - expand_head(env, funct.exp_type), - List.length(args), - ), - ), - ) - | td => + (t_args, t_ret); + | TTyArrow(t_args, t_ret, _) => (t_args, t_ret) + | _ => raise( Error( funct.exp_loc, @@ -1721,15 +1617,185 @@ and type_application = (~in_function=?, env, funct, args) => { ) }; - let typed_args = - type_arguments( - ~in_function?, - env, - args, + let ordered_labels = List.map(fst, ty_args); + + let (labeled_sargs, unlabeled_sargs) = + List.partition( + sarg => { + switch (sarg.paa_label) { + | Labeled(_) => true + | _ => false + } + }, + sargs, + ); + + let (used_labeled_tyargs, unused_tyargs) = + List.partition( + ((l, _)) => { + List.exists( + sarg => same_label_name(l, sarg.paa_label), + labeled_sargs, + ) + }, ty_args, - List.map(instance(env), ty_args), ); - (typed_args, instance(env, ty_ret)); + + let rec type_args = + ( + args, + remaining_sargs, + remaining_used_labeled_tyargs, + remaining_unused_tyargs, + ) => { + let rec extract_label = (l, tyargs) => { + switch (tyargs) { + | [] => (None, []) + | [(tyl, _) as tyarg, ...rest_tyargs] when same_label_name(tyl, l) => ( + Some(tyarg), + rest_tyargs, + ) + | [tyarg, ...rest_tyargs] => + let (res, rest_tyargs) = extract_label(l, rest_tyargs); + (res, [tyarg, ...rest_tyargs]); + }; + }; + let rec next_tyarg = tyargs => { + switch (tyargs) { + | [] => (None, []) + | [(tyl, _) as tyarg, ...rest_tyargs] when !is_optional(tyl) => ( + Some(tyarg), + rest_tyargs, + ) + | [tyarg, ...rest_tyargs] => + let (res, rest_tyargs) = next_tyarg(rest_tyargs); + (res, [tyarg, ...rest_tyargs]); + }; + }; + switch (remaining_sargs) { + | [] => (args, remaining_unused_tyargs) + | [sarg, ...remaining_sargs] => + let ( + corresponding_tyarg, + remaining_used_labeled_tyargs, + remaining_unused_tyargs, + ) = + switch (sarg.paa_label) { + | Default(_) => + failwith("Impossible: optional argument in application") + | Labeled(_) => + let (corresponding_tyarg, remaining_used_labeled_tyargs) = + extract_label(sarg.paa_label, remaining_used_labeled_tyargs); + ( + corresponding_tyarg, + remaining_used_labeled_tyargs, + remaining_unused_tyargs, + ); + | Unlabeled => + let (corresponding_tyarg, remaining_unused_tyargs) = + next_tyarg(remaining_unused_tyargs); + ( + corresponding_tyarg, + remaining_used_labeled_tyargs, + remaining_unused_tyargs, + ); + }; + switch (corresponding_tyarg) { + | Some((l, ty)) => + let arg = + if (!is_optional(l)) { + ( + () => + type_argument( + ~in_function?, + env, + sarg.paa_expr, + ty, + instance(env, ty), + ) + ); + } else { + ( + () => + option_some( + env, + type_argument( + ~in_function?, + env, + sarg.paa_expr, + extract_option_type(env, ty), + extract_option_type(env, instance(env, ty)), + ), + ) + ); + }; + type_args( + [(l, arg), ...args], + remaining_sargs, + remaining_used_labeled_tyargs, + remaining_unused_tyargs, + ); + | None => + switch (sarg.paa_label) { + | Unlabeled => + raise( + Error( + loc, + env, + Apply_too_many_arguments( + expand_head(env, funct.exp_type), + unused_tyargs, + ), + ), + ) + | _ => + raise( + Error( + sarg.paa_loc, + env, + Apply_unknown_label( + label_name(sarg.paa_label), + List.filter_map( + l => { + switch (l) { + | Unlabeled => None + | _ => Some(label_name(l)) + } + }, + ordered_labels, + ), + ), + ), + ) + } + }; + }; + }; + + let (args, remaining_tyargs) = + type_args([], sargs, used_labeled_tyargs, unused_tyargs); + + let omitted_args = + List.map( + ((l, ty)) => { + switch (l) { + | Default(_) => + // omitted optional argument + (l, option_none(env, instance(env, ty), Location.dummy_loc)) + | _ => + let missing_args = + List.filter(((l, _)) => !is_optional(l), remaining_tyargs); + raise(Error(loc, env, Apply_too_few_arguments(missing_args))); + } + }, + remaining_tyargs, + ); + + // Typecheck all arguments. + // Order here is important; rev_map would be incorrect. + let typed_args = List.map(((l, argf)) => (l, argf()), List.rev(args)); + + (ordered_labels, omitted_args @ typed_args, instance(env, ty_ret)); } and type_construct = (env, loc, lid, sarg, ty_expected_explained, attrs) => { @@ -1850,7 +1916,13 @@ and type_construct = (env, loc, lid, sarg, ty_expected_explained, attrs) => { raise (Error(loc, env, Inlined_record_expected)) end*/ - let args = type_arguments(~recarg, env, sargs, ty_args, ty_args0); + let args = + List.map2( + (sarg, (ty_arg, ty_arg0)) => + type_argument(~recarg, env, sarg, ty_arg, ty_arg0), + sargs, + List.combine(ty_args, ty_args0), + ); let arg = if (is_record_cstr) { switch (args) { @@ -2472,9 +2544,7 @@ and type_label_exp = (create, env, loc, ty_expected, (lid, label, sarg)) => { } else { Some(Btype.snapshot()); }; - let arg = - List.hd @@ - type_arguments(env, [sarg], [ty_arg], [instance(env, ty_arg)]); + let arg = type_argument(env, sarg, ty_arg, instance(env, ty_arg)); end_def(); try( { @@ -2606,7 +2676,7 @@ let report_error = (env, ppf) => | Constructor_arity_mismatch(lid, expected, provided) => fprintf( ppf, - "@[The constructor %a@ expects %i argument(s),@ but is applied here to %i argument(s)@]", + "@[The constructor %a@ expects %i argument(s),@ but is called with %i argument(s)@]", identifier, lid, expected, @@ -2681,29 +2751,96 @@ let report_error = (env, ppf) => ) | Apply_non_function(typ) => { reset_and_mark_loops(typ); - switch (repr(typ).desc) { - | TTyArrow(_) => + fprintf( + ppf, + "@[@[<2>This expression has type@ %a@]@ %s@]", + type_expr, + typ, + "This is not a function; it cannot be called.", + ); + } + | Apply_too_many_arguments(typ, unused_tyargs) => { + reset_and_mark_loops(typ); + fprintf(ppf, "@[@[<2>This function has type@ %a@]", type_expr, typ); + fprintf(ppf, "@ @[It is called with too many arguments.@]@]"); + let unused_optional_arguments = + List.filter_map( + ((l, _)) => + switch (l) { + | Default({txt: name}) => Some(name) + | _ => None + }, + unused_tyargs, + ); + let oxford = (ppf, args) => { + let rec oxford = (ppf, args) => + switch (args) { + | [] => () + | [arg1, arg2] => fprintf(ppf, "%s, or %s", arg1, arg2) + | [arg1, ...args] => + fprintf(ppf, "%s, ", arg1); + oxford(ppf, args); + }; + + switch (args) { + | [] => () + | [arg] => fprintf(ppf, "%s", arg) + | [arg1, arg2] => fprintf(ppf, "%s or %s", arg1, arg2) + | _ => oxford(ppf, args) + }; + }; + switch (unused_optional_arguments) { + | [] => () + | labels => fprintf( ppf, - "@[@[<2>This function has type@ %a@]", - type_expr, - typ, - ); + "@ @[Did you mean to supply an argument with label %a?@]@]", + oxford, + unused_optional_arguments, + ) + }; + } + | Apply_too_few_arguments(args) => { + List.iter(((_, typ)) => reset_and_mark_loops(typ), args); + let print_arg = ((l, arg)) => { + reset_and_mark_loops(arg); + switch (l) { + | Unlabeled => fprintf(ppf, "%a", type_expr, arg) + | _ => + fprintf(ppf, "%s: %a", qualified_label_name(l), type_expr, arg) + }; + }; + let rec print_args = (ppf, args) => { + switch (args) { + | [] => () + | [arg] => print_arg(arg) + | [arg, ...rest] => + print_arg(arg); + fprintf(ppf, ",@ "); + print_args(ppf, rest); + }; + }; + switch (args) { + | [arg] => fprintf( ppf, - "@ @[It is applied to too many arguments;@ %s@]@]", - "maybe you forgot a `;'.", - ); + "@[This function call is missing an argument of type %a@]", + print_args, + args, + ) | _ => fprintf( ppf, - "@[@[<2>This expression has type@ %a@]@ %s@]", - type_expr, - typ, - "This is not a function; it cannot be applied.", + "@[This function call is missing arguments of type %a@]", + print_args, + args, ) }; } + | Apply_unknown_label(label, valid_labels) => { + fprintf(ppf, "This argument cannot be supplied with label %s.", label); + spellcheck(ppf, label, valid_labels); + } | Label_multiply_defined(s) => fprintf(ppf, "The record field label %s is defined several times", s) | Label_missing(labels) => { @@ -2720,19 +2857,17 @@ let report_error = (env, ppf) => fprintf(ppf, "The record field %a is not mutable", identifier, lid) | Assign_not_mutable(id) => fprintf(ppf, "The identifier %a was not declared mutable", identifier, id) - | Arity_mismatch(typ, arity) => - fprintf( - ppf, - "@[The type %a cannot be called with %d argument%s@]", - Printtyp.type_expr, - typ, - arity, - if (arity == 1) { - ""; - } else { - "s"; - }, - ) + | Arity_mismatch(ty, explanation) => { + reset_and_mark_loops(ty); + fprintf(ppf, "This function expects the wrong number of arguments,@ "); + fprintf( + ppf, + "it should have type@ %a%t", + type_expr, + ty, + report_type_expected_explanation_opt(explanation), + ); + } | Wrong_name(eorp, ty_expected, kind, p, name, valid_names) => { let {ty, explanation} = ty_expected; reset_and_mark_loops(ty); @@ -2857,27 +2992,43 @@ let report_error = (env, ppf) => ); }; } - | Too_many_arguments(in_function, ty, explanation) => { + | Not_a_function(ty, explanation) => { reset_and_mark_loops(ty); - if (in_function) { - fprintf(ppf, "This function expects too many arguments,@ "); + fprintf(ppf, "This expression is not a function,@ "); + fprintf( + ppf, + "the expected type is@ %a%t", + type_expr, + ty, + report_type_expected_explanation_opt(explanation), + ); + } + | Function_label_mismatch({got, expected, expected_type, explanation}) => { + reset_and_mark_loops(expected_type); + if (is_optional(got)) { fprintf( ppf, - "it should have type@ %a%t", - type_expr, - ty, - report_type_expected_explanation_opt(explanation), + "This function contains the argument %s@ ", + qualified_label_name(got), ); } else { - fprintf(ppf, "This expression should not be a function,@ "); fprintf( ppf, - "the expected type is@ %a%t", - type_expr, - ty, - report_type_expected_explanation_opt(explanation), + "The expected function type contains the argument %s@ ", + qualified_label_name(expected), ); }; + fprintf( + ppf, + "which has a default value, but the matching argument does not.@ ", + ); + fprintf( + ppf, + "The expected type is@ %a%t", + type_expr, + expected_type, + report_type_expected_explanation_opt(explanation), + ); } | Scoping_let_module(id, ty) => { reset_and_mark_loops(ty); @@ -2914,7 +3065,7 @@ let report_error = (env, ppf) => | Not_a_variant_type(lid) => fprintf(ppf, "The type %a@ is not a variant type", identifier, lid) | Incoherent_label_order => { - fprintf(ppf, "This function is applied to arguments@ "); + fprintf(ppf, "This function is called with arguments@ "); fprintf(ppf, "in an order different from other calls.@ "); fprintf(ppf, "This is only allowed when the real type is known."); } @@ -3042,5 +3193,3 @@ let () = let type_expect = (~in_function=?, env, e, ty) => type_expect(~in_function?, env, e, ty); let type_exp = (env, e) => type_exp(env, e); -let type_arguments = (env, es, t1s, t2s) => - type_arguments(env, es, t1s, t2s); diff --git a/compiler/src/typed/typecore.rei b/compiler/src/typed/typecore.rei index 2455113cf4..cc0c30ad9d 100644 --- a/compiler/src/typed/typecore.rei +++ b/compiler/src/typed/typecore.rei @@ -62,16 +62,13 @@ let type_expect: Typedtree.expression; let type_exp: (Env.t, Parsetree.expression) => Typedtree.expression; let type_approx: (Env.t, Parsetree.expression) => type_expr; -let type_arguments: - (Env.t, list(Parsetree.expression), list(type_expr), list(type_expr)) => - list(Typedtree.expression); let generalizable: (int, type_expr) => bool; let name_pattern: (string, list(Typedtree.match_branch)) => Ident.t; type error = - | Arity_mismatch(type_expr, int) + | Arity_mismatch(type_expr, option(Checkertypes.type_forcing_context)) | Polymorphic_label(Identifier.t) | Constructor_arity_mismatch(Identifier.t, int, int) | Label_mismatch(Identifier.t, list((type_expr, type_expr))) @@ -84,6 +81,9 @@ type error = option(Checkertypes.type_forcing_context), ) | Apply_non_function(type_expr) + | Apply_too_many_arguments(type_expr, list((argument_label, type_expr))) + | Apply_too_few_arguments(list((argument_label, type_expr))) + | Apply_unknown_label(string, list(string)) | Label_multiply_defined(string) | Label_missing(list(Ident.t)) | Label_not_mutable(Identifier.t) @@ -122,11 +122,13 @@ type error = list((type_expr, type_expr)), bool, ) - | Too_many_arguments( - bool, - type_expr, - option(Checkertypes.type_forcing_context), - ) + | Not_a_function(type_expr, option(Checkertypes.type_forcing_context)) + | Function_label_mismatch({ + got: argument_label, + expected: argument_label, + expected_type: type_expr, + explanation: option(Checkertypes.type_forcing_context), + }) | Scoping_let_module(string, type_expr) | Masked_instance_variable(Identifier.t) | Not_a_variant_type(Identifier.t) diff --git a/compiler/src/typed/typed_well_formedness.re b/compiler/src/typed/typed_well_formedness.re index b204a7bbea..1e228dd676 100644 --- a/compiler/src/typed/typed_well_formedness.re +++ b/compiler/src/typed/typed_well_formedness.re @@ -89,7 +89,7 @@ let ensure_no_escaped_types = (signature, statements) => { | TTyVar(_) | TTyUniVar(_) => () | TTyArrow(args, res, _) => - List.iter(check_type, args); + List.iter(((_, arg)) => check_type(arg), args); check_type(res); | TTyTuple(args) => List.iter(check_type, args) | TTyRecord(fields) => @@ -223,10 +223,11 @@ module WellFormednessArg: TypedtreeIter.IteratorArgument = { _, ), }, + _, args, ) when func == "==" || func == "!=" => - if (List.exists(exp_is_wasm_unsafe, args)) { + if (List.exists(((_, arg)) => exp_is_wasm_unsafe(arg), args)) { let warning = Grain_utils.Warnings.FuncWasmUnsafe( Printf.sprintf("Pervasives.(%s)", func), @@ -245,15 +246,19 @@ module WellFormednessArg: TypedtreeIter.IteratorArgument = { _, ), }, + _, [ - { - exp_desc: - TExpConstant( - Const_number( - (Const_number_int(_) | Const_number_float(_)) as n, + ( + Unlabeled, + { + exp_desc: + TExpConstant( + Const_number( + (Const_number_int(_) | Const_number_float(_)) as n, + ), ), - ), - }, + }, + ), ], ) when diff --git a/compiler/src/typed/typedecl.re b/compiler/src/typed/typedecl.re index 4defb92f07..2c9d70b1b3 100644 --- a/compiler/src/typed/typedecl.re +++ b/compiler/src/typed/typedecl.re @@ -54,7 +54,6 @@ type error = /*| Unbound_type_var_ext of type_expr * extension_constructor*/ | Varying_anonymous | Val_in_structure - | Multiple_native_repr_attributes | Cannot_unbox_or_untag_type(native_repr_kind) | Deep_unbox_or_untag_attribute(native_repr_kind) | Bad_immediate_attribute @@ -868,39 +867,6 @@ let transl_data_decl = (env, rec_flag, sdecl_list) => { (final_decls, final_env); }; -type native_repr_attribute = - | Native_repr_attr_absent - | Native_repr_attr_present(native_repr_kind); - -let get_native_repr_attribute = (attrs, ~global_repr) => - /*Attr_helper.get_no_payload_attribute ["unboxed"; "ocaml.unboxed"] attrs, - Attr_helper.get_no_payload_attribute ["untagged"; "ocaml.untagged"] attrs,*/ - switch (None, None, global_repr) { - | (None, None, None) => Native_repr_attr_absent - | (None, None, Some(repr)) => Native_repr_attr_present(repr) - | (Some(_), None, None) => Native_repr_attr_present(Unboxed) - | (None, Some(_), None) => Native_repr_attr_present(Untagged) - | (Some({Location.loc}), _, _) - | (_, Some({Location.loc}), _) => - raise(Error(loc, Multiple_native_repr_attributes)) - }; - -let native_repr_of_type = (env, kind, ty) => - switch (kind, Ctype.expand_head_opt(env, ty).desc) { - | (Untagged, TTyConstr(path, _, _)) - when Path.same(path, Builtin_types.path_number) => - Some(Untagged_int) - /*| Unboxed, TTyConstr (path, _, _) when Path.same path Predef.path_float -> - Some Unboxed_float - | Unboxed, TTyConstr (path, _, _) when Path.same path Predef.path_int32 -> - Some (Unboxed_integer Pint32) - | Unboxed, TTyConstr (path, _, _) when Path.same path Predef.path_int64 -> - Some (Unboxed_integer Pint64) - | Unboxed, TTyConstr (path, _, _) when Path.same path Predef.path_nativeint -> - Some (Unboxed_integer Pnativeint)*/ - | _ => None - }; - /* Translate a value declaration */ let transl_value_decl = (env, loc, valdecl) => { let cty = Typetexp.transl_type_scheme(env, valdecl.pval_type); @@ -1421,8 +1387,6 @@ let report_error = ppf => ) | Val_in_structure => fprintf(ppf, "Value declarations are only allowed in signatures") - | Multiple_native_repr_attributes => - fprintf(ppf, "Too many [@@unboxed]/[@@untagged] attributes") | Cannot_unbox_or_untag_type(Unboxed) => fprintf( ppf, diff --git a/compiler/src/typed/typedtree.re b/compiler/src/typed/typedtree.re index bc1acdccc1..4f2ab9d99f 100644 --- a/compiler/src/typed/typedtree.re +++ b/compiler/src/typed/typedtree.re @@ -40,6 +40,9 @@ type provide_flag = Asttypes.provide_flag = | NotProvided | Provided | Abstract; type rec_flag = Asttypes.rec_flag = | Nonrecursive | Recursive; type mut_flag = Asttypes.mut_flag = | Mutable | Immutable; +type argument_label = + Asttypes.argument_label = + | Unlabeled | Labeled(loc(string)) | Default(loc(string)); type wasm_prim_type = Parsetree.wasm_prim_type = @@ -328,7 +331,7 @@ type core_type = { and core_type_desc = | TTyAny | TTyVar(string) - | TTyArrow(list(core_type), core_type) + | TTyArrow(list((argument_label, core_type)), core_type) | TTyTuple(list(core_type)) | TTyRecord(list((loc(Identifier.t), core_type))) | TTyConstr(Path.t, loc(Identifier.t), list(core_type)) @@ -493,7 +496,11 @@ and expression_desc = | TExpBreak | TExpReturn(option(expression)) | TExpLambda(list(match_branch), partial) - | TExpApp(expression, list(expression)) + | TExpApp( + expression, + list(argument_label), + list((argument_label, expression)), + ) | TExpConstruct( loc(Identifier.t), constructor_description, diff --git a/compiler/src/typed/typedtree.rei b/compiler/src/typed/typedtree.rei index a7035bfc0f..dfde5e3b85 100644 --- a/compiler/src/typed/typedtree.rei +++ b/compiler/src/typed/typedtree.rei @@ -40,6 +40,9 @@ type provide_flag = Asttypes.provide_flag = | NotProvided | Provided | Abstract; type rec_flag = Asttypes.rec_flag = | Nonrecursive | Recursive; type mut_flag = Asttypes.mut_flag = | Mutable | Immutable; +type argument_label = + Asttypes.argument_label = + | Unlabeled | Labeled(loc(string)) | Default(loc(string)); type wasm_prim_type = Parsetree.wasm_prim_type = @@ -308,7 +311,7 @@ type core_type = { and core_type_desc = | TTyAny | TTyVar(string) - | TTyArrow(list(core_type), core_type) + | TTyArrow(list((argument_label, core_type)), core_type) | TTyTuple(list(core_type)) | TTyRecord(list((loc(Identifier.t), core_type))) | TTyConstr(Path.t, loc(Identifier.t), list(core_type)) @@ -461,7 +464,11 @@ and expression_desc = | TExpBreak | TExpReturn(option(expression)) | TExpLambda(list(match_branch), partial) - | TExpApp(expression, list(expression)) + | TExpApp( + expression, + list(argument_label), + list((argument_label, expression)), + ) | TExpConstruct( loc(Identifier.t), constructor_description, diff --git a/compiler/src/typed/typedtreeIter.re b/compiler/src/typed/typedtreeIter.re index 0981e2067b..2e1a2d6b1d 100644 --- a/compiler/src/typed/typedtreeIter.re +++ b/compiler/src/typed/typedtreeIter.re @@ -63,7 +63,7 @@ module MakeIterator = | TTyAny | TTyVar(_) => () | TTyArrow(args, ret) => - List.iter(iter_core_type, args); + List.iter(((_, a)) => iter_core_type(a), args); iter_core_type(ret); | TTyConstr(_, _, args) | TTyTuple(args) => List.iter(iter_core_type, args) @@ -208,9 +208,9 @@ module MakeIterator = | TExpLet(recflag, mutflag, binds) => iter_bindings(recflag, mutflag, binds) | TExpLambda(branches, _) => iter_match_branches(branches) - | TExpApp(exp, args) => + | TExpApp(exp, _, args) => iter_expression(exp); - List.iter(iter_expression, args); + List.iter(((_, arg)) => iter_expression(arg), args); | TExpPrim0(_) => () | TExpPrim1(_, e) => iter_expression(e) | TExpPrim2(_, e1, e2) => diff --git a/compiler/src/typed/typedtreeMap.re b/compiler/src/typed/typedtreeMap.re index c92d4a5e57..d2dad743a4 100644 --- a/compiler/src/typed/typedtreeMap.re +++ b/compiler/src/typed/typedtreeMap.re @@ -56,7 +56,7 @@ module MakeMap = | TTyAny | TTyVar(_) => ct.ctyp_desc | TTyArrow(args, ret) => - let args = List.map(map_core_type, args); + let args = List.map(((l, arg)) => (l, map_core_type(arg)), args); let ret = map_core_type(ret); TTyArrow(args, ret); | TTyConstr(a, b, args) => @@ -211,8 +211,12 @@ module MakeMap = TExpLet(recflag, mutflag, map_bindings(recflag, mutflag, binds)) | TExpLambda(branches, p) => TExpLambda(map_match_branches(branches), p) - | TExpApp(exp, args) => - TExpApp(map_expression(exp), List.map(map_expression, args)) + | TExpApp(exp, labels, args) => + TExpApp( + map_expression(exp), + labels, + List.map(((l, arg)) => (l, map_expression(arg)), args), + ) | TExpPrim0(o) => TExpPrim0(o) | TExpPrim1(o, e) => TExpPrim1(o, map_expression(e)) | TExpPrim2(o, e1, e2) => diff --git a/compiler/src/typed/typemod.re b/compiler/src/typed/typemod.re index 94de1cd785..ea047a6037 100644 --- a/compiler/src/typed/typemod.re +++ b/compiler/src/typed/typemod.re @@ -752,7 +752,7 @@ let rec type_module = (~toplevel=false, anchor, env, statements) => { ...expr, desc: TTyArrow( - List.map(resolve_type_expr, args), + List.map(((l, arg)) => (l, resolve_type_expr(arg)), args), resolve_type_expr(result), c, ), diff --git a/compiler/src/typed/types.re b/compiler/src/typed/types.re index ea3e8c8dea..a8f8000ed0 100644 --- a/compiler/src/typed/types.re +++ b/compiler/src/typed/types.re @@ -38,7 +38,7 @@ type type_expr = { and type_desc = | TTyVar(option(string)) // A type variable (None == "_") - | TTyArrow(list(type_expr), type_expr, commutable) // A function type. + | TTyArrow(list((argument_label, type_expr)), type_expr, commutable) // A function type. | TTyTuple(list(type_expr)) // A tuple type. | TTyRecord(list((string, type_expr))) // A record type. | TTyConstr(Path.t, list(type_expr), ref(abbrev_memo)) // A parameterized type. diff --git a/compiler/src/typed/typetexp.re b/compiler/src/typed/typetexp.re index bc306e41af..619dee1f9f 100644 --- a/compiler/src/typed/typetexp.re +++ b/compiler/src/typed/typetexp.re @@ -338,12 +338,37 @@ and transl_type_aux = (env, policy, styp) => { }; ctyp(TTyVar(name), ty); - | PTyArrow(st1, st2) => - let cty1 = List.map(transl_type(env, policy), st1); + | PTyArrow(stl, st2) => + let ctyl = + List.map( + st => { + let ty = transl_type(env, policy, st.ptyp_arg_type); + (st.ptyp_arg_label, ty); + }, + stl, + ); + let tyl = + List.map( + ((l, ty)) => { + let ty = + if (Btype.is_optional(l)) { + newty( + TTyConstr( + Builtin_types.path_option, + [ty.ctyp_type], + ref(TMemNil), + ), + ); + } else { + ty.ctyp_type; + }; + (l, ty); + }, + ctyl, + ); let cty2 = transl_type(env, policy, st2); - let ty1 = List.map(x => x.ctyp_type, cty1); - let ty = newty(TTyArrow(ty1, cty2.ctyp_type, TComOk)); - ctyp(TTyArrow(cty1, cty2), ty); + let ty = newty(TTyArrow(tyl, cty2.ctyp_type, TComOk)); + ctyp(TTyArrow(ctyl, cty2), ty); | PTyTuple(stl) => assert(List.length(stl) >= 1); let ctys = List.map(transl_type(env, policy), stl); @@ -602,62 +627,6 @@ let type_attributes = attrs => { ); }; -let rec type_expr_to_core_type = (env, expr) => { - let desc = - switch (expr.desc) { - | TTyVar(None) => TTyAny - | TTyVar(Some(name)) => TTyVar(name) - | TTyArrow(args, result, _) => - TTyArrow( - List.map(type_expr_to_core_type(env), args), - type_expr_to_core_type(env, result), - ) - | TTyTuple(args) => - TTyTuple(List.map(type_expr_to_core_type(env), args)) - | TTyRecord(fields) => - TTyRecord( - List.map( - ((field, ty)) => - ( - Location.mknoloc( - Identifier.IdentName(Location.mknoloc(field)), - ), - type_expr_to_core_type(env, ty), - ), - fields, - ), - ) - | TTyConstr(path, args, _) => - TTyConstr( - path, - Location.mknoloc( - Identifier.IdentName(Location.mknoloc(Path.name(path))), - ), - List.map(type_expr_to_core_type(env), args), - ) - | TTyUniVar(Some(name)) => TTyVar(name) - | TTyUniVar(None) => TTyAny - | TTyPoly(ty, args) => - TTyPoly( - List.map( - fun - | {desc: TTyVar(Some(name))} => name - | _ => failwith("TTyPoly invalid type vars"), - args, - ), - type_expr_to_core_type(env, ty), - ) - | TTyLink(ty) => type_expr_to_core_type(env, ty).ctyp_desc - | TTySubst(ty) => type_expr_to_core_type(env, ty).ctyp_desc - }; - { - ctyp_desc: desc, - ctyp_type: expr, - ctyp_env: env, - ctyp_loc: Location.dummy_loc, - }; -}; - let report_error = (env, ppf) => fun | Unbound_type_variable(name) => diff --git a/compiler/src/typed/typetexp.rei b/compiler/src/typed/typetexp.rei index b190dfbba8..7851244170 100644 --- a/compiler/src/typed/typetexp.rei +++ b/compiler/src/typed/typetexp.rei @@ -113,5 +113,3 @@ let type_attributes: Asttypes.attributes => Typedtree.attributes; let unbound_label_error: (Env.t, Location.loc(Identifier.t)) => 'a; let unbound_constructor_error: (Env.t, Location.loc(Identifier.t)) => 'a; - -let type_expr_to_core_type: (Env.t, type_expr) => Typedtree.core_type; diff --git a/compiler/test/suites/functions.re b/compiler/test/suites/functions.re index ff31e749da..5dccf90870 100644 --- a/compiler/test/suites/functions.re +++ b/compiler/test/suites/functions.re @@ -56,7 +56,11 @@ describe("functions", ({test, testSkip}) => { "let rec foo = (() => {5});\nlet bar = (() => { 7 });\nlet rec foo = (() => {9});\nfoo()", ); assertCompileError("arity_1", "let foo = (() => {5});\nfoo(6)", "type"); - assertCompileError("arity_2", "let foo = ((x) => {x + 5});\nfoo()", "type"); + assertCompileError( + "arity_2", + "let foo = ((x) => {x + 5});\nfoo()", + "missing an argument of type x: Number", + ); assertCompileError( "arity_3", "let foo = ((x) => {x});\nfoo(1, 2, 3)", @@ -135,7 +139,11 @@ describe("functions", ({test, testSkip}) => { "((x, y, x) => {5})", "Variable x is bound several times", ); - assertCompileError("lambda_arity_1", "((x) => {6})()", "type"); + assertCompileError( + "lambda_arity_1", + "((x) => {6})()", + "missing an argument", + ); assertCompileError("lambda_arity_2", "((x) => {5})(1, 2)", "type"); assertCompileError( "letrec_nonstatic_const", @@ -206,4 +214,152 @@ truc()|}, foo() |}, ); + + assertRun( + "labeled_args1", + {| + let concat = (a, b) => a ++ b + print(concat(a="1", b="2")) + |}, + "12\n", + ); + assertRun( + "labeled_args2", + {| + let concat = (a, b) => a ++ b + print(concat(a="1", "2")) + |}, + "12\n", + ); + assertRun( + "labeled_args3", + {| + let concat = (a, b) => a ++ b + print(concat("2", a="1")) + |}, + "12\n", + ); + assertRun( + "labeled_args4", + {| + let concat = (a, b) => a ++ b + print(concat("1", b="2")) + |}, + "12\n", + ); + assertRun( + "labeled_args5", + {| + let concat = (a, b) => a ++ b + print(concat(b="2", "1")) + |}, + "12\n", + ); + assertRun( + "labeled_args6", + {| + let nothing = (a, b) => void + nothing(b=print(1), print(2)) + |}, + "1\n2\n", + ); + + assertRun( + "default_args1", + {| + let concat = (a="1", b) => a ++ b + print(concat(a="3", "2")) + |}, + "32\n", + ); + assertRun( + "default_args2", + {| + let concat = (a="1", b) => a ++ b + print(concat(a="3", b="2")) + |}, + "32\n", + ); + assertRun( + "default_args3", + {| + let concat = (a="1", b) => a ++ b + print(concat(b="2", a="3")) + |}, + "32\n", + ); + assertRun( + "default_args4", + {| + let concat = (a="1", b) => a ++ b + print(concat("2")) + |}, + "12\n", + ); + assertRun( + "default_args5", + {| + let concat = (a="1", b) => a ++ b + print(concat(b="2")) + |}, + "12\n", + ); + assertRun( + "default_args6", + {| + let concat = (a=b ++ b, b) => a ++ b + print(concat(b="9")) + |}, + "999\n", + ); + + assertRun( + "labeled_args_typecheck1", + {| + let apply = (f: (arg1: Number) -> Number) => f(arg1=5) + print(apply(notarg1 => notarg1)) + |}, + "5\n", + ); + + assertCompileError( + "labeled_args_err1", + {| + let concat = (a, b) => a ++ b + print(concat(c="3")) + |}, + "This argument cannot be supplied with label c", + ); + assertCompileError( + "labeled_args_err2", + {| + let concat = (a, b) => a ++ b + print(concat("1", "2", c="3")) + |}, + "This argument cannot be supplied with label c", + ); + assertCompileError( + "labeled_args_err3", + {| + let concat = (a="1", b) => a ++ b + print(concat("1", "2")) + |}, + "Did you mean to supply an argument with label a?", + ); + assertCompileError( + "labeled_args_err4", + {| + let apply = (f: (?arg1: Number) -> Number) => f(arg1=5) + print(apply(notarg1 => notarg1)) + |}, + "The expected function type contains the argument \\?arg1", + ); + assertCompileError( + "labeled_args_err5", + {| + let apply = (f: (?arg1: Number) -> Number) => f(arg1=5) + print(apply(notarg1 => notarg1)) + |}, + "which has a default value, but the matching argument does not.", + ); }); diff --git a/compiler/test/suites/parsing.re b/compiler/test/suites/parsing.re index ee47f50339..32af362557 100644 --- a/compiler/test/suites/parsing.re +++ b/compiler/test/suites/parsing.re @@ -2,6 +2,7 @@ open Grain_tests.TestFramework; open Grain_tests.Runner; open Grain_parsing; open Grain_parsing.Ast_helper; +open Grain_parsing.Parsetree; describe("parsing", ({test, testSkip}) => { let test_or_skip = @@ -28,6 +29,11 @@ describe("parsing", ({test, testSkip}) => { Expression.ident( Location.mknoloc(Identifier.IdentName(Location.mknoloc("c"))), ); + let unlabled_expr = expr => { + paa_label: Unlabeled, + paa_expr: expr, + paa_loc: Location.dummy_loc, + }; let testOp = op => assertParse( op, @@ -42,7 +48,7 @@ describe("parsing", ({test, testSkip}) => { Identifier.IdentName(Location.mknoloc(op)), ), ), - [a, b], + [unlabled_expr(a), unlabled_expr(b)], ), ), ], @@ -112,14 +118,16 @@ describe("parsing", ({test, testSkip}) => { ), ), [ - a, - Expression.apply( - Expression.ident( - Location.mknoloc( - Identifier.IdentName(Location.mknoloc("***")), + unlabled_expr(a), + unlabled_expr( + Expression.apply( + Expression.ident( + Location.mknoloc( + Identifier.IdentName(Location.mknoloc("***")), + ), ), + [unlabled_expr(b), unlabled_expr(c)], ), - [b, c], ), ], ), @@ -143,14 +151,16 @@ describe("parsing", ({test, testSkip}) => { ), ), [ - a, - Expression.apply( - Expression.ident( - Location.mknoloc( - Identifier.IdentName(Location.mknoloc("&--")), + unlabled_expr(a), + unlabled_expr( + Expression.apply( + Expression.ident( + Location.mknoloc( + Identifier.IdentName(Location.mknoloc("&--")), + ), ), + [unlabled_expr(b), unlabled_expr(c)], ), - [b, c], ), ], ), @@ -174,14 +184,16 @@ describe("parsing", ({test, testSkip}) => { ), ), [ - a, - Expression.apply( - Expression.ident( - Location.mknoloc( - Identifier.IdentName(Location.mknoloc("|--")), + unlabled_expr(a), + unlabled_expr( + Expression.apply( + Expression.ident( + Location.mknoloc( + Identifier.IdentName(Location.mknoloc("|--")), + ), ), + [unlabled_expr(b), unlabled_expr(c)], ), - [b, c], ), ], ), @@ -205,15 +217,17 @@ describe("parsing", ({test, testSkip}) => { ), ), [ - Expression.apply( - Expression.ident( - Location.mknoloc( - Identifier.IdentName(Location.mknoloc("<<")), + unlabled_expr( + Expression.apply( + Expression.ident( + Location.mknoloc( + Identifier.IdentName(Location.mknoloc("<<")), + ), ), + [unlabled_expr(a), unlabled_expr(b)], ), - [a, b], ), - c, + unlabled_expr(c), ], ), ), diff --git a/stdlib/array.md b/stdlib/array.md index 0c630c44e4..d8912f77bd 100644 --- a/stdlib/array.md +++ b/stdlib/array.md @@ -33,7 +33,7 @@ No other changes yet. ```grain -length : Array -> Number +length : (array: Array) -> Number ``` Provides the length of the input array. @@ -152,7 +152,7 @@ Array.init(5, n => n + 3) // [> 3, 4, 5, 6, 7] ```grain -get : (Number, Array) -> a +get : (index: Number, array: Array) -> a ``` An alias for normal syntactic array access, i.e. `array[n]`. @@ -201,7 +201,7 @@ Array.get(1,[> 1, 2, 3, 4, 5]) == 2 ```grain -set : (Number, a, Array) -> Void +set : (index: Number, value: a, array: Array) -> Void ``` An alias for normal syntactic array set, i.e. `array[n] = value`. @@ -238,7 +238,7 @@ No other changes yet. ```grain -append : (Array, Array) -> Array +append : (array1: Array, array2: Array) -> Array ``` Creates a new array with the elements of the first array followed by @@ -277,7 +277,7 @@ No other changes yet. ```grain -concat : List> -> Array +concat : (arrays: List>) -> Array ``` Creates a single array containing the elements of all arrays in the @@ -315,7 +315,7 @@ No other changes yet. ```grain -copy : Array -> Array +copy : (array: Array) -> Array ``` Produces a shallow copy of the input array. The new array contains the @@ -341,7 +341,7 @@ No other changes yet. ```grain -cycle : ((a -> Void), Number, Array) -> Void +cycle : (fn: (a -> Void), n: Number, array: Array) -> Void ``` Iterates an array a given number of times, calling an iterator function on each element. @@ -369,7 +369,7 @@ Parameters: ```grain -forEach : ((a -> Void), Array) -> Void +forEach : (fn: (a -> Void), array: Array) -> Void ``` Iterates an array, calling an iterator function on each element. @@ -396,7 +396,7 @@ Parameters: ```grain -forEachi : (((a, Number) -> Void), Array) -> Void +forEachi : (fn: ((a, Number) -> Void), array: Array) -> Void ``` Iterates an array, calling an iterator function on each element. @@ -424,7 +424,7 @@ Parameters: ```grain -map : ((a -> b), Array) -> Array +map : (fn: (a -> b), array: Array) -> Array ``` Produces a new array initialized with the results of a mapper function @@ -451,7 +451,7 @@ No other changes yet. ```grain -mapi : (((a, Number) -> b), Array) -> Array +mapi : (fn: ((a, Number) -> b), array: Array) -> Array ``` Produces a new array initialized with the results of a mapper function @@ -478,7 +478,7 @@ No other changes yet. ```grain -reduce : (((a, b) -> a), a, Array) -> a +reduce : (fn: ((a, b) -> a), initial: a, array: Array) -> a ``` Combines all elements of an array using a reducer function, @@ -517,7 +517,7 @@ No other changes yet. ```grain -reduceRight : (((a, b) -> b), b, Array) -> b +reduceRight : (fn: ((a, b) -> b), initial: b, array: Array) -> b ``` Combines all elements of an array using a reducer function, @@ -556,7 +556,7 @@ No other changes yet. ```grain -reducei : (((a, b, Number) -> a), a, Array) -> a +reducei : (fn: ((a, b, Number) -> a), initial: a, array: Array) -> a ``` Combines all elements of an array using a reducer function, @@ -590,7 +590,7 @@ No other changes yet. ```grain -flatMap : ((b -> Array), Array) -> Array +flatMap : (fn: (b -> Array), array: Array) -> Array ``` Produces a new array by calling a function on each element @@ -625,7 +625,7 @@ No other changes yet. ```grain -every : ((a -> Bool), Array) -> Bool +every : (fn: (a -> Bool), array: Array) -> Bool ``` Checks that the given condition is satisfied for all @@ -652,7 +652,7 @@ No other changes yet. ```grain -some : ((a -> Bool), Array) -> Bool +some : (fn: (a -> Bool), array: Array) -> Bool ``` Checks that the given condition is satisfied **at least @@ -679,7 +679,7 @@ No other changes yet. ```grain -fill : (a, Array) -> Void +fill : (value: a, array: Array) -> Void ``` Replaces all elements in an array with the new value provided. @@ -699,7 +699,7 @@ No other changes yet. ```grain -fillRange : (a, Number, Number, Array) -> Void +fillRange : (value: a, start: Number, stop: Number, array: Array) -> Void ``` Replaces all elements in the provided index range in the array @@ -729,7 +729,7 @@ No other changes yet. ```grain -reverse : Array -> Array +reverse : (array: Array) -> Array ``` Creates a new array with all elements in reverse order. @@ -754,7 +754,7 @@ No other changes yet. ```grain -toList : Array -> List +toList : (array: Array) -> List ``` Converts the input array to a list. @@ -779,7 +779,7 @@ No other changes yet. ```grain -fromList : List -> Array +fromList : (list: List) -> Array ``` Converts the input list to an array. @@ -804,7 +804,7 @@ No other changes yet. ```grain -contains : (a, Array) -> Bool +contains : (search: a, array: Array) -> Bool ``` Checks if the value is an element of the input array. @@ -831,7 +831,7 @@ No other changes yet. ```grain -find : ((a -> Bool), Array) -> Option +find : (fn: (a -> Bool), array: Array) -> Option ``` Finds the first element in an array that satifies the given condition. @@ -857,7 +857,7 @@ No other changes yet. ```grain -findIndex : ((a -> Bool), Array) -> Option +findIndex : (fn: (a -> Bool), array: Array) -> Option ``` Finds the first index in an array where the element satifies the given condition. @@ -883,7 +883,7 @@ No other changes yet. ```grain -product : (Array, Array) -> Array<(a, b)> +product : (array1: Array, array2: Array) -> Array<(a, b)> ``` Combines two arrays into a Cartesian product of tuples containing @@ -916,7 +916,7 @@ No other changes yet. ```grain -count : ((a -> Bool), Array) -> Number +count : (fn: (a -> Bool), array: Array) -> Number ``` Counts the number of elements in an array that satisfy the given condition. @@ -942,7 +942,7 @@ No other changes yet. ```grain -counti : (((a, Number) -> Bool), Array) -> Number +counti : (fn: ((a, Number) -> Bool), array: Array) -> Number ``` Counts the number of elements in an array that satisfy the @@ -969,7 +969,7 @@ No other changes yet. ```grain -filter : ((a -> Bool), Array) -> Array +filter : (fn: (a -> Bool), array: Array) -> Array ``` Produces a new array by calling a function on each element of @@ -997,7 +997,7 @@ No other changes yet. ```grain -filteri : (((a, Number) -> Bool), Array) -> Array +filteri : (fn: ((a, Number) -> Bool), array: Array) -> Array ``` Produces a new array by calling a function on each element of @@ -1025,7 +1025,7 @@ No other changes yet. ```grain -unique : Array -> Array +unique : (array: Array) -> Array ``` Produces a new array with any duplicates removed. @@ -1058,7 +1058,7 @@ Returns: ```grain -zip : (Array, Array) -> Array<(a, b)> +zip : (array1: Array, array2: Array) -> Array<(a, b)> ``` Produces a new array filled with tuples of elements from both given arrays. @@ -1092,7 +1092,7 @@ No other changes yet. ```grain -zipWith : (((a, b) -> c), Array, Array) -> Array +zipWith : (fn: ((a, b) -> c), array1: Array, array2: Array) -> Array ``` Produces a new array filled with elements defined by applying a function on @@ -1142,7 +1142,7 @@ No other changes yet. ```grain -unzip : Array<(a, b)> -> (Array, Array) +unzip : (array: Array<(a, b)>) -> (Array, Array) ``` Produces two arrays by splitting apart an array of tuples. @@ -1167,7 +1167,7 @@ No other changes yet. ```grain -join : (String, Array) -> String +join : (separator: String, items: Array) -> String ``` Concatenates an array of strings into a single string, separated by a separator string. @@ -1193,7 +1193,7 @@ No other changes yet. ```grain -slice : (Number, Number, Array) -> Array +slice : (startIndex: Number, endIndex: Number, array: Array) -> Array ``` Slices an array given zero-based start and end indexes. The value @@ -1224,7 +1224,7 @@ No other changes yet. ```grain -sort : (((a, a) -> Number), Array) -> Void +sort : (comp: ((a, a) -> Number), array: Array) -> Void ``` Sorts an array in-place. @@ -1253,7 +1253,7 @@ Parameters: ```grain -rotate : (Number, Array) -> Void +rotate : (n: Number, arr: Array) -> Void ``` Rotates array elements in place by the specified amount to the left, such diff --git a/stdlib/bigint.md b/stdlib/bigint.md index 7200172161..bce587d579 100644 --- a/stdlib/bigint.md +++ b/stdlib/bigint.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> BigInt +fromNumber : (x: Number) -> BigInt ``` Converts a Number to a BigInt. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : BigInt -> Number +toNumber : (x: BigInt) -> Number ``` Converts a BigInt to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -incr : BigInt -> BigInt +incr : (num: BigInt) -> BigInt ``` Increments the value by one. @@ -100,7 +100,7 @@ No other changes yet. ```grain -decr : BigInt -> BigInt +decr : (num: BigInt) -> BigInt ``` Decrements the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -neg : BigInt -> BigInt +neg : (num: BigInt) -> BigInt ``` Negates the given operand. @@ -150,7 +150,7 @@ No other changes yet. ```grain -abs : BigInt -> BigInt +abs : (num: BigInt) -> BigInt ``` Returns the absolute value of the given operand. @@ -182,7 +182,7 @@ Returns: ```grain -(+) : (BigInt, BigInt) -> BigInt +(+) : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the sum of its operands. @@ -215,7 +215,7 @@ Returns: ```grain -(-) : (BigInt, BigInt) -> BigInt +(-) : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the difference of its operands. @@ -248,7 +248,7 @@ Returns: ```grain -(*) : (BigInt, BigInt) -> BigInt +(*) : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the product of its operands. @@ -281,7 +281,7 @@ Returns: ```grain -(/) : (BigInt, BigInt) -> BigInt +(/) : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the quotient of its operands using signed (truncated) division @@ -308,7 +308,7 @@ No other changes yet. ```grain -rem : (BigInt, BigInt) -> BigInt +rem : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the remainder of the division of its operands using signed (truncated) division @@ -335,7 +335,7 @@ No other changes yet. ```grain -quotRem : (BigInt, BigInt) -> (BigInt, BigInt) +quotRem : (num1: BigInt, num2: BigInt) -> (BigInt, BigInt) ``` Computes the quotient and remainder of its operands using signed (truncated) division. @@ -361,7 +361,7 @@ No other changes yet. ```grain -gcd : (BigInt, BigInt) -> BigInt +gcd : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the greatest common divisior of the two operands. @@ -394,7 +394,7 @@ Returns: ```grain -(<<) : (BigInt, Int32) -> BigInt +(<<) : (num: BigInt, places: Int32) -> BigInt ``` Shifts the bits of the value left by the given number of bits. @@ -427,7 +427,7 @@ Returns: ```grain -(>>) : (BigInt, Int32) -> BigInt +(>>) : (num: BigInt, places: Int32) -> BigInt ``` Shifts the bits of the value right by the given number of bits, preserving the sign bit. @@ -453,7 +453,7 @@ No other changes yet. ```grain -eqz : BigInt -> Bool +eqz : (num: BigInt) -> Bool ``` Checks if the given value is equal to zero. @@ -485,7 +485,7 @@ Returns: ```grain -(==) : (BigInt, BigInt) -> Bool +(==) : (num1: BigInt, num2: BigInt) -> Bool ``` Checks if the first value is equal to the second value. @@ -518,7 +518,7 @@ Returns: ```grain -(!=) : (BigInt, BigInt) -> Bool +(!=) : (num1: BigInt, num2: BigInt) -> Bool ``` Checks if the first value is not equal to the second value. @@ -551,7 +551,7 @@ Returns: ```grain -(<) : (BigInt, BigInt) -> Bool +(<) : (num1: BigInt, num2: BigInt) -> Bool ``` Checks if the first value is less than the second value. @@ -584,7 +584,7 @@ Returns: ```grain -(<=) : (BigInt, BigInt) -> Bool +(<=) : (num1: BigInt, num2: BigInt) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -617,7 +617,7 @@ Returns: ```grain -(>) : (BigInt, BigInt) -> Bool +(>) : (num1: BigInt, num2: BigInt) -> Bool ``` Checks if the first value is greater than the second value. @@ -650,7 +650,7 @@ Returns: ```grain -(>=) : (BigInt, BigInt) -> Bool +(>=) : (num1: BigInt, num2: BigInt) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -676,7 +676,7 @@ No other changes yet. ```grain -lnot : BigInt -> BigInt +lnot : (num: BigInt) -> BigInt ``` Computes the bitwise NOT of the given value. @@ -708,7 +708,7 @@ Returns: ```grain -(&) : (BigInt, BigInt) -> BigInt +(&) : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the bitwise AND (`&`) on the given operands. @@ -741,7 +741,7 @@ Returns: ```grain -(|) : (BigInt, BigInt) -> BigInt +(|) : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the bitwise OR (`|`) on the given operands. @@ -774,7 +774,7 @@ Returns: ```grain -(^) : (BigInt, BigInt) -> BigInt +(^) : (num1: BigInt, num2: BigInt) -> BigInt ``` Computes the bitwise XOR (`^`) on the given operands. @@ -800,7 +800,7 @@ No other changes yet. ```grain -clz : BigInt -> Int32 +clz : (num: BigInt) -> Int32 ``` Counts the number of leading zero bits in the value. @@ -826,7 +826,7 @@ No other changes yet. ```grain -ctz : BigInt -> Int64 +ctz : (num: BigInt) -> Int64 ``` Counts the number of trailing zero bits in the value. @@ -851,7 +851,7 @@ No other changes yet. ```grain -popcnt : BigInt -> Option +popcnt : (num: BigInt) -> Option ``` Counts the number of bits set to `1` in the value, also known as a population count. @@ -877,7 +877,7 @@ No other changes yet. ```grain -toString : BigInt -> String +toString : (num: BigInt) -> String ``` Converts the given operand to a string. diff --git a/stdlib/buffer.md b/stdlib/buffer.md index 91ce9cd3ab..0e23abfee9 100644 --- a/stdlib/buffer.md +++ b/stdlib/buffer.md @@ -37,7 +37,7 @@ No other changes yet. ```grain -make : Number -> Buffer +make : (initialSize: Number) -> Buffer ``` Creates a fresh buffer, initially empty. @@ -71,7 +71,7 @@ No other changes yet. ```grain -length : Buffer -> Number +length : (buffer: Buffer) -> Number ``` Gets the number of bytes currently contained in a buffer. @@ -96,7 +96,7 @@ No other changes yet. ```grain -clear : Buffer -> Void +clear : (buffer: Buffer) -> Void ``` Clears data in the buffer and sets its length to zero. @@ -117,7 +117,7 @@ No other changes yet. ```grain -reset : Buffer -> Void +reset : (buffer: Buffer) -> Void ``` Empty a buffer and deallocate the internal byte sequence holding the buffer contents. @@ -138,7 +138,7 @@ No other changes yet. ```grain -truncate : (Number, Buffer) -> Void +truncate : (length: Number, buffer: Buffer) -> Void ``` Shortens a buffer to the given length. @@ -167,7 +167,7 @@ No other changes yet. ```grain -toBytes : Buffer -> Bytes +toBytes : (buffer: Buffer) -> Bytes ``` Returns a copy of the current contents of the buffer as a byte sequence. @@ -192,7 +192,7 @@ No other changes yet. ```grain -toBytesSlice : (Number, Number, Buffer) -> Bytes +toBytesSlice : (start: Number, length: Number, buffer: Buffer) -> Bytes ``` Returns a slice of the current contents of the buffer as a byte sequence. @@ -227,7 +227,7 @@ No other changes yet. ```grain -toString : Buffer -> String +toString : (buffer: Buffer) -> String ``` Returns a copy of the current contents of the buffer as a string. @@ -252,7 +252,7 @@ No other changes yet. ```grain -toStringSlice : (Number, Number, Buffer) -> String +toStringSlice : (start: Number, length: Number, buffer: Buffer) -> String ``` Returns a copy of a subset of the current contents of the buffer as a string. @@ -279,7 +279,7 @@ No other changes yet. ```grain -addBytes : (Bytes, Buffer) -> Void +addBytes : (bytes: Bytes, buffer: Buffer) -> Void ``` Appends a byte sequence to a buffer. @@ -299,7 +299,7 @@ No other changes yet. ```grain -addString : (String, Buffer) -> Void +addString : (string: String, buffer: Buffer) -> Void ``` Appends the bytes of a string to a buffer. @@ -319,7 +319,7 @@ No other changes yet. ```grain -addChar : (Char, Buffer) -> Void +addChar : (char: Char, buffer: Buffer) -> Void ``` Appends the bytes of a char to a buffer. @@ -346,7 +346,8 @@ Parameters: ```grain -addStringSlice : (Number, Number, String, Buffer) -> Void +addStringSlice : + (start: Number, end: Number, string: String, buffer: Buffer) -> Void ``` Appends the bytes of a subset of a string to a buffer. @@ -368,7 +369,8 @@ No other changes yet. ```grain -addBytesSlice : (Number, Number, Bytes, Buffer) -> Void +addBytesSlice : + (start: Number, length: Number, bytes: Bytes, buffer: Buffer) -> Void ``` Appends the bytes of a subset of a byte sequence to a buffer. @@ -399,7 +401,7 @@ No other changes yet. ```grain -addBuffer : (Buffer, Buffer) -> Void +addBuffer : (srcBuffer: Buffer, dstBuffer: Buffer) -> Void ``` Appends the bytes of a source buffer to destination buffer. @@ -421,7 +423,9 @@ No other changes yet. ```grain -addBufferSlice : (Number, Number, Buffer, Buffer) -> Void +addBufferSlice : + (start: Number, length: Number, srcBuffer: Buffer, dstBuffer: Buffer) -> + Void ``` Appends the bytes of a part of a buffer to the end of the buffer @@ -452,7 +456,7 @@ Parameters: ```grain -getInt8 : (Number, Buffer) -> Int8 +getInt8 : (index: Number, buffer: Buffer) -> Int8 ``` Gets a signed 8-bit integer starting at the given byte index. @@ -493,7 +497,7 @@ Throws: ```grain -setInt8 : (Number, Int8, Buffer) -> Void +setInt8 : (index: Number, value: Int8, buffer: Buffer) -> Void ``` Sets a signed 8-bit integer starting at the given byte index. @@ -529,7 +533,7 @@ Throws: ```grain -addInt8 : (Int8, Buffer) -> Void +addInt8 : (value: Int8, buffer: Buffer) -> Void ``` Appends a signed 8-bit integer to a buffer. @@ -556,7 +560,7 @@ Parameters: ```grain -getUint8 : (Number, Buffer) -> Uint8 +getUint8 : (index: Number, buffer: Buffer) -> Uint8 ``` Gets an unsigned 8-bit integer starting at the given byte index. @@ -590,7 +594,7 @@ No other changes yet. ```grain -setUint8 : (Number, Uint8, Buffer) -> Void +setUint8 : (index: Number, value: Uint8, buffer: Buffer) -> Void ``` Sets an unsigned 8-bit integer starting at the given byte index. @@ -619,7 +623,7 @@ No other changes yet. ```grain -addUint8 : (Uint8, Buffer) -> Void +addUint8 : (value: Uint8, buffer: Buffer) -> Void ``` Appends an unsigned 8-bit integer to a buffer. @@ -646,7 +650,7 @@ Parameters: ```grain -getInt16 : (Number, Buffer) -> Int16 +getInt16 : (index: Number, buffer: Buffer) -> Int16 ``` Gets a signed 16-bit integer starting at the given byte index. @@ -687,7 +691,7 @@ Throws: ```grain -setInt16 : (Number, Int16, Buffer) -> Void +setInt16 : (index: Number, value: Int16, buffer: Buffer) -> Void ``` Sets a signed 16-bit integer starting at the given byte index. @@ -723,7 +727,7 @@ Throws: ```grain -addInt16 : (Int16, Buffer) -> Void +addInt16 : (value: Int16, buffer: Buffer) -> Void ``` Appends a signed 16-bit integer to a buffer. @@ -750,7 +754,7 @@ Parameters: ```grain -getUint16 : (Number, Buffer) -> Uint16 +getUint16 : (index: Number, buffer: Buffer) -> Uint16 ``` Gets an unsigned 16-bit integer starting at the given byte index. @@ -784,7 +788,7 @@ No other changes yet. ```grain -setUint16 : (Number, Uint16, Buffer) -> Void +setUint16 : (index: Number, value: Uint16, buffer: Buffer) -> Void ``` Sets an unsigned 16-bit integer starting at the given byte index. @@ -813,7 +817,7 @@ No other changes yet. ```grain -addUint16 : (Uint16, Buffer) -> Void +addUint16 : (value: Uint16, buffer: Buffer) -> Void ``` Appends an unsigned 16-bit integer to a buffer. @@ -833,7 +837,7 @@ No other changes yet. ```grain -getInt32 : (Number, Buffer) -> Int32 +getInt32 : (index: Number, buffer: Buffer) -> Int32 ``` Gets a signed 32-bit integer starting at the given byte index. @@ -867,7 +871,7 @@ No other changes yet. ```grain -setInt32 : (Number, Int32, Buffer) -> Void +setInt32 : (index: Number, value: Int32, buffer: Buffer) -> Void ``` Sets a signed 32-bit integer starting at the given byte index. @@ -896,7 +900,7 @@ No other changes yet. ```grain -addInt32 : (Int32, Buffer) -> Void +addInt32 : (value: Int32, buffer: Buffer) -> Void ``` Appends a signed 32-bit integer to a buffer. @@ -916,7 +920,7 @@ No other changes yet. ```grain -getUint32 : (Number, Buffer) -> Uint32 +getUint32 : (index: Number, buffer: Buffer) -> Uint32 ``` Gets an unsigned 32-bit integer starting at the given byte index. @@ -950,7 +954,7 @@ No other changes yet. ```grain -setUint32 : (Number, Uint32, Buffer) -> Void +setUint32 : (index: Number, value: Uint32, buffer: Buffer) -> Void ``` Sets an unsigned 32-bit integer starting at the given byte index. @@ -979,7 +983,7 @@ No other changes yet. ```grain -addUint32 : (Uint32, Buffer) -> Void +addUint32 : (value: Uint32, buffer: Buffer) -> Void ``` Appends an unsigned 32-bit integer to a buffer. @@ -999,7 +1003,7 @@ No other changes yet. ```grain -getFloat32 : (Number, Buffer) -> Float32 +getFloat32 : (index: Number, buffer: Buffer) -> Float32 ``` Gets a 32-bit float starting at the given byte index. @@ -1033,7 +1037,7 @@ No other changes yet. ```grain -setFloat32 : (Number, Float32, Buffer) -> Void +setFloat32 : (index: Number, value: Float32, buffer: Buffer) -> Void ``` Sets a 32-bit float starting at the given byte index. @@ -1062,7 +1066,7 @@ No other changes yet. ```grain -addFloat32 : (Float32, Buffer) -> Void +addFloat32 : (value: Float32, buffer: Buffer) -> Void ``` Appends a 32-bit float to a buffer. @@ -1082,7 +1086,7 @@ No other changes yet. ```grain -getInt64 : (Number, Buffer) -> Int64 +getInt64 : (index: Number, buffer: Buffer) -> Int64 ``` Gets a signed 64-bit integer starting at the given byte index. @@ -1116,7 +1120,7 @@ No other changes yet. ```grain -setInt64 : (Number, Int64, Buffer) -> Void +setInt64 : (index: Number, value: Int64, buffer: Buffer) -> Void ``` Sets a signed 64-bit integer starting at the given byte index. @@ -1145,7 +1149,7 @@ No other changes yet. ```grain -addInt64 : (Int64, Buffer) -> Void +addInt64 : (value: Int64, buffer: Buffer) -> Void ``` Appends a signed 64-bit integer to a buffer. @@ -1165,7 +1169,7 @@ No other changes yet. ```grain -getUint64 : (Number, Buffer) -> Uint64 +getUint64 : (index: Number, buffer: Buffer) -> Uint64 ``` Gets an unsigned 64-bit integer starting at the given byte index. @@ -1199,7 +1203,7 @@ No other changes yet. ```grain -setUint64 : (Number, Uint64, Buffer) -> Void +setUint64 : (index: Number, value: Uint64, buffer: Buffer) -> Void ``` Sets an unsigned 64-bit integer starting at the given byte index. @@ -1228,7 +1232,7 @@ No other changes yet. ```grain -addUint64 : (Uint64, Buffer) -> Void +addUint64 : (value: Uint64, buffer: Buffer) -> Void ``` Appends an unsigned 64-bit integer to a buffer. @@ -1248,7 +1252,7 @@ No other changes yet. ```grain -getFloat64 : (Number, Buffer) -> Float64 +getFloat64 : (index: Number, buffer: Buffer) -> Float64 ``` Gets a 64-bit float starting at the given byte index. @@ -1282,7 +1286,7 @@ No other changes yet. ```grain -setFloat64 : (Number, Float64, Buffer) -> Void +setFloat64 : (index: Number, value: Float64, buffer: Buffer) -> Void ``` Sets a 64-bit float starting at the given byte index. @@ -1311,7 +1315,7 @@ No other changes yet. ```grain -addFloat64 : (Float64, Buffer) -> Void +addFloat64 : (value: Float64, buffer: Buffer) -> Void ``` Appends a 64-bit float to a buffer. diff --git a/stdlib/bytes.md b/stdlib/bytes.md index 0216fc7a29..be85f0e912 100644 --- a/stdlib/bytes.md +++ b/stdlib/bytes.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -make : Number -> Bytes +make : (size: Number) -> Bytes ``` Creates a new byte sequence of the input size. @@ -63,7 +63,7 @@ No other changes yet. ```grain -fromString : String -> Bytes +fromString : (string: String) -> Bytes ``` Creates a new byte sequence from the input string. @@ -88,7 +88,7 @@ No other changes yet. ```grain -toString : Bytes -> String +toString : (bytes: Bytes) -> String ``` Creates a new string from the input bytes. @@ -113,7 +113,7 @@ No other changes yet. ```grain -length : Bytes -> Number +length : (bytes: Bytes) -> Number ``` Returns the length of a byte sequence. @@ -138,7 +138,7 @@ No other changes yet. ```grain -copy : Bytes -> Bytes +copy : (b: Bytes) -> Bytes ``` Creates a new byte sequence that contains the same bytes as the input byte sequence. @@ -163,7 +163,7 @@ No other changes yet. ```grain -slice : (Number, Number, Bytes) -> Bytes +slice : (start: Number, length: Number, bytes: Bytes) -> Bytes ``` Returns a copy of a subset of the input byte sequence. @@ -196,7 +196,7 @@ No other changes yet. ```grain -resize : (Number, Number, Bytes) -> Bytes +resize : (left: Number, right: Number, bytes: Bytes) -> Bytes ``` Returns a copy of a byte sequence with bytes added or removed from the beginning and/or end. @@ -231,7 +231,9 @@ No other changes yet. ```grain -move : (Number, Number, Number, Bytes, Bytes) -> Void +move : + (srcIndex: Number, dstIndex: Number, length: Number, src: Bytes, dst: Bytes) -> + Void ``` Copies a range of bytes from a source byte sequence to a given location @@ -262,7 +264,7 @@ No other changes yet. ```grain -concat : (Bytes, Bytes) -> Bytes +concat : (bytes1: Bytes, bytes2: Bytes) -> Bytes ``` Creates a new byte sequence that contains the bytes of both byte sequences. @@ -295,7 +297,7 @@ Returns: ```grain -fill : (Uint8, Bytes) -> Void +fill : (value: Uint8, bytes: Bytes) -> Void ``` Replaces all bytes in a byte sequnce with the new value provided. @@ -315,7 +317,7 @@ No other changes yet. ```grain -clear : Bytes -> Void +clear : (bytes: Bytes) -> Void ``` Replaces all bytes in a byte sequence with zeroes. @@ -341,7 +343,7 @@ Parameters: ```grain -getInt8 : (Number, Bytes) -> Int8 +getInt8 : (index: Number, bytes: Bytes) -> Int8 ``` Gets a signed 8-bit integer starting at the given byte index. @@ -381,7 +383,7 @@ Throws: ```grain -setInt8 : (Number, Int8, Bytes) -> Void +setInt8 : (index: Number, value: Int8, bytes: Bytes) -> Void ``` Sets a signed 8-bit integer starting at the given byte index. @@ -416,7 +418,7 @@ Throws: ```grain -getUint8 : (Number, Bytes) -> Uint8 +getUint8 : (index: Number, bytes: Bytes) -> Uint8 ``` Gets an unsigned 8-bit integer starting at the given byte index. @@ -449,7 +451,7 @@ No other changes yet. ```grain -setUint8 : (Number, Uint8, Bytes) -> Void +setUint8 : (index: Number, value: Uint8, bytes: Bytes) -> Void ``` Sets an unsigned 8-bit integer starting at the given byte index. @@ -484,7 +486,7 @@ Throws: ```grain -getInt16 : (Number, Bytes) -> Int16 +getInt16 : (index: Number, bytes: Bytes) -> Int16 ``` Gets a signed 16-bit integer starting at the given byte index. @@ -524,7 +526,7 @@ Throws: ```grain -setInt16 : (Number, Int16, Bytes) -> Void +setInt16 : (index: Number, value: Int16, bytes: Bytes) -> Void ``` Sets a signed 16-bit integer starting at the given byte index. @@ -559,7 +561,7 @@ Throws: ```grain -getUint16 : (Number, Bytes) -> Uint16 +getUint16 : (index: Number, bytes: Bytes) -> Uint16 ``` Gets an unsigned 16-bit integer starting at the given byte index. @@ -592,7 +594,7 @@ No other changes yet. ```grain -setUint16 : (Number, Uint16, Bytes) -> Void +setUint16 : (index: Number, value: Uint16, bytes: Bytes) -> Void ``` Sets an unsigned 16-bit integer starting at the given byte index. @@ -620,7 +622,7 @@ No other changes yet. ```grain -getInt32 : (Number, Bytes) -> Int32 +getInt32 : (index: Number, bytes: Bytes) -> Int32 ``` Gets a signed 32-bit integer starting at the given byte index. @@ -653,7 +655,7 @@ No other changes yet. ```grain -setInt32 : (Number, Int32, Bytes) -> Void +setInt32 : (index: Number, value: Int32, bytes: Bytes) -> Void ``` Sets a signed 32-bit integer starting at the given byte index. @@ -681,7 +683,7 @@ No other changes yet. ```grain -getUint32 : (Number, Bytes) -> Uint32 +getUint32 : (index: Number, bytes: Bytes) -> Uint32 ``` Gets an unsigned 32-bit integer starting at the given byte index. @@ -714,7 +716,7 @@ No other changes yet. ```grain -setUint32 : (Number, Uint32, Bytes) -> Void +setUint32 : (index: Number, value: Uint32, bytes: Bytes) -> Void ``` Sets an unsigned 32-bit integer starting at the given byte index. @@ -742,7 +744,7 @@ No other changes yet. ```grain -getFloat32 : (Number, Bytes) -> Float32 +getFloat32 : (index: Number, bytes: Bytes) -> Float32 ``` Gets a 32-bit float starting at the given byte index. @@ -775,7 +777,7 @@ No other changes yet. ```grain -setFloat32 : (Number, Float32, Bytes) -> Void +setFloat32 : (index: Number, value: Float32, bytes: Bytes) -> Void ``` Sets a 32-bit float starting at the given byte index. @@ -803,7 +805,7 @@ No other changes yet. ```grain -getInt64 : (Number, Bytes) -> Int64 +getInt64 : (index: Number, bytes: Bytes) -> Int64 ``` Gets a signed 64-bit integer starting at the given byte index. @@ -836,7 +838,7 @@ No other changes yet. ```grain -setInt64 : (Number, Int64, Bytes) -> Void +setInt64 : (index: Number, value: Int64, bytes: Bytes) -> Void ``` Sets a signed 64-bit integer starting at the given byte index. @@ -864,7 +866,7 @@ No other changes yet. ```grain -getUint64 : (Number, Bytes) -> Uint64 +getUint64 : (index: Number, bytes: Bytes) -> Uint64 ``` Gets an unsigned 64-bit integer starting at the given byte index. @@ -897,7 +899,7 @@ No other changes yet. ```grain -setUint64 : (Number, Uint64, Bytes) -> Void +setUint64 : (index: Number, value: Uint64, bytes: Bytes) -> Void ``` Sets an unsigned 64-bit integer starting at the given byte index. @@ -925,7 +927,7 @@ No other changes yet. ```grain -getFloat64 : (Number, Bytes) -> Float64 +getFloat64 : (index: Number, bytes: Bytes) -> Float64 ``` Gets a 64-bit float starting at the given byte index. @@ -958,7 +960,7 @@ No other changes yet. ```grain -setFloat64 : (Number, Float64, Bytes) -> Void +setFloat64 : (index: Number, value: Float64, bytes: Bytes) -> Void ``` Sets a 64-bit float starting at the given byte index. diff --git a/stdlib/char.md b/stdlib/char.md index f7683f9edf..71125eb669 100644 --- a/stdlib/char.md +++ b/stdlib/char.md @@ -53,7 +53,7 @@ No other changes yet. ```grain -isValid : Number -> Bool +isValid : (charCode: Number) -> Bool ``` Determines whether the given character code is a valid Unicode scalar value. @@ -78,7 +78,7 @@ No other changes yet. ```grain -code : Char -> Number +code : (char: Char) -> Number ``` Determines the Unicode scalar value for a character. @@ -103,7 +103,7 @@ No other changes yet. ```grain -fromCode : Number -> Char +fromCode : (usv: Number) -> Char ``` Creates a character from the given Unicode scalar value. @@ -134,7 +134,7 @@ No other changes yet. ```grain -succ : Char -> Char +succ : (char: Char) -> Char ``` Returns the next valid character by Unicode scalar value. @@ -165,7 +165,7 @@ No other changes yet. ```grain -pred : Char -> Char +pred : (char: Char) -> Char ``` Returns the previous valid character by Unicode scalar value. @@ -196,7 +196,7 @@ No other changes yet. ```grain -toString : Char -> String +toString : (char: Char) -> String ``` Converts the given character to a string. diff --git a/stdlib/exception.md b/stdlib/exception.md index 4f401feb32..2a8b9475d5 100644 --- a/stdlib/exception.md +++ b/stdlib/exception.md @@ -27,7 +27,7 @@ No other changes yet. ```grain -registerPrinter : (Exception -> Option) -> Void +registerPrinter : (printer: (Exception -> Option)) -> Void ``` Registers an exception printer. When an exception is thrown, all registered diff --git a/stdlib/float32.md b/stdlib/float32.md index 679be259cb..502b063402 100644 --- a/stdlib/float32.md +++ b/stdlib/float32.md @@ -90,7 +90,7 @@ No other changes yet. ```grain -fromNumber : Number -> Float32 +fromNumber : (x: Number) -> Float32 ``` Converts a Number to a Float32. @@ -115,7 +115,7 @@ No other changes yet. ```grain -toNumber : Float32 -> Number +toNumber : (x: Float32) -> Number ``` Converts a Float32 to a Number. @@ -140,7 +140,7 @@ No other changes yet. ```grain -add : (Float32, Float32) -> Float32 +add : (x: Float32, y: Float32) -> Float32 ``` Computes the sum of its operands. @@ -166,7 +166,7 @@ No other changes yet. ```grain -sub : (Float32, Float32) -> Float32 +sub : (x: Float32, y: Float32) -> Float32 ``` Computes the difference of its operands. @@ -192,7 +192,7 @@ No other changes yet. ```grain -mul : (Float32, Float32) -> Float32 +mul : (x: Float32, y: Float32) -> Float32 ``` Computes the product of its operands. @@ -218,7 +218,7 @@ No other changes yet. ```grain -div : (Float32, Float32) -> Float32 +div : (x: Float32, y: Float32) -> Float32 ``` Computes the quotient of its operands. @@ -244,7 +244,7 @@ No other changes yet. ```grain -lt : (Float32, Float32) -> Bool +lt : (x: Float32, y: Float32) -> Bool ``` Checks if the first value is less than the second value. @@ -270,7 +270,7 @@ No other changes yet. ```grain -gt : (Float32, Float32) -> Bool +gt : (x: Float32, y: Float32) -> Bool ``` Checks if the first value is greater than the second value. @@ -296,7 +296,7 @@ No other changes yet. ```grain -lte : (Float32, Float32) -> Bool +lte : (x: Float32, y: Float32) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -322,7 +322,7 @@ No other changes yet. ```grain -gte : (Float32, Float32) -> Bool +gte : (x: Float32, y: Float32) -> Bool ``` Checks if the first value is greater than or equal to the second value. diff --git a/stdlib/float64.md b/stdlib/float64.md index f46f9b0a8a..8e552dc5c3 100644 --- a/stdlib/float64.md +++ b/stdlib/float64.md @@ -90,7 +90,7 @@ No other changes yet. ```grain -fromNumber : Number -> Float64 +fromNumber : (x: Number) -> Float64 ``` Converts a Number to a Float64. @@ -115,7 +115,7 @@ No other changes yet. ```grain -toNumber : Float64 -> Number +toNumber : (x: Float64) -> Number ``` Converts a Float64 to a Number. @@ -140,7 +140,7 @@ No other changes yet. ```grain -add : (Float64, Float64) -> Float64 +add : (x: Float64, y: Float64) -> Float64 ``` Computes the sum of its operands. @@ -166,7 +166,7 @@ No other changes yet. ```grain -sub : (Float64, Float64) -> Float64 +sub : (x: Float64, y: Float64) -> Float64 ``` Computes the difference of its operands. @@ -192,7 +192,7 @@ No other changes yet. ```grain -mul : (Float64, Float64) -> Float64 +mul : (x: Float64, y: Float64) -> Float64 ``` Computes the product of its operands. @@ -218,7 +218,7 @@ No other changes yet. ```grain -div : (Float64, Float64) -> Float64 +div : (x: Float64, y: Float64) -> Float64 ``` Computes the quotient of its operands. @@ -244,7 +244,7 @@ No other changes yet. ```grain -lt : (Float64, Float64) -> Bool +lt : (x: Float64, y: Float64) -> Bool ``` Checks if the first value is less than the second value. @@ -270,7 +270,7 @@ No other changes yet. ```grain -gt : (Float64, Float64) -> Bool +gt : (x: Float64, y: Float64) -> Bool ``` Checks if the first value is greater than the second value. @@ -296,7 +296,7 @@ No other changes yet. ```grain -lte : (Float64, Float64) -> Bool +lte : (x: Float64, y: Float64) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -322,7 +322,7 @@ No other changes yet. ```grain -gte : (Float64, Float64) -> Bool +gte : (x: Float64, y: Float64) -> Bool ``` Checks if the first value is greater than or equal to the second value. diff --git a/stdlib/hash.md b/stdlib/hash.md index a9aa5ac355..b6f23cdedf 100644 --- a/stdlib/hash.md +++ b/stdlib/hash.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -hash : a -> Number +hash : (anything: a) -> Number ``` A generic hash function that produces an integer from any value. If `a == b` then `Hash.hash(a) == Hash.hash(b)`. diff --git a/stdlib/immutablearray.md b/stdlib/immutablearray.md index 9f21da69fe..061f5b75aa 100644 --- a/stdlib/immutablearray.md +++ b/stdlib/immutablearray.md @@ -48,7 +48,7 @@ No other changes yet. ```grain -isEmpty : ImmutableArray -> Bool +isEmpty : (array: ImmutableArray) -> Bool ``` Determines if the array contains no elements. @@ -73,7 +73,7 @@ No other changes yet. ```grain -length : ImmutableArray -> Number +length : (array: ImmutableArray) -> Number ``` Provides the length of the input array. @@ -104,7 +104,7 @@ No other changes yet. ```grain -get : (Number, ImmutableArray) -> a +get : (index: Number, array: ImmutableArray) -> a ``` Retrieves the element from the array at the specified index. @@ -147,7 +147,8 @@ No other changes yet. ```grain -set : (Number, a, ImmutableArray) -> ImmutableArray +set : + (index: Number, value: a, array: ImmutableArray) -> ImmutableArray ``` Creates a new array in which the element at the specified index is set to a @@ -187,7 +188,8 @@ No other changes yet. ```grain -append : (ImmutableArray, ImmutableArray) -> ImmutableArray +append : + (array1: ImmutableArray, array2: ImmutableArray) -> ImmutableArray ``` Creates a new array with the elements of the first array followed by @@ -220,7 +222,7 @@ No other changes yet. ```grain -concat : List> -> ImmutableArray +concat : (arrays: List>) -> ImmutableArray ``` Creates a single array containing the elements of all arrays in the @@ -252,7 +254,7 @@ No other changes yet. ```grain -init : (Number, (Number -> a)) -> ImmutableArray +init : (length: Number, fn: (Number -> a)) -> ImmutableArray ``` Creates a new array of the specified length where each element is @@ -286,7 +288,7 @@ No other changes yet. ```grain -make : (Number, a) -> ImmutableArray +make : (length: Number, value: a) -> ImmutableArray ``` Creates a new array of the specified length with each element being @@ -319,7 +321,7 @@ No other changes yet. ```grain -forEach : ((a -> Void), ImmutableArray) -> Void +forEach : (fn: (a -> Void), array: ImmutableArray) -> Void ``` Iterates an array, calling an iterator function on each element. @@ -339,7 +341,7 @@ No other changes yet. ```grain -cycle : ((a -> Void), Number, ImmutableArray) -> Void +cycle : (fn: (a -> Void), n: Number, array: ImmutableArray) -> Void ``` Iterates an array a given number of times, calling an iterator function on each element. @@ -360,7 +362,7 @@ No other changes yet. ```grain -map : ((a -> b), ImmutableArray) -> ImmutableArray +map : (fn: (a -> b), array: ImmutableArray) -> ImmutableArray ``` Produces a new array initialized with the results of a mapper function @@ -387,7 +389,7 @@ No other changes yet. ```grain -reduce : (((a, b) -> a), a, ImmutableArray) -> a +reduce : (fn: ((a, b) -> a), initial: a, array: ImmutableArray) -> a ``` Combines all elements of an array using a reducer function, @@ -426,7 +428,7 @@ No other changes yet. ```grain -reduceRight : (((a, b) -> b), b, ImmutableArray) -> b +reduceRight : (fn: ((a, b) -> b), initial: b, array: ImmutableArray) -> b ``` Combines all elements of an array using a reducer function, @@ -465,7 +467,9 @@ No other changes yet. ```grain -flatMap : ((a -> ImmutableArray), ImmutableArray) -> ImmutableArray +flatMap : + (fn: (a -> ImmutableArray), array: ImmutableArray) -> + ImmutableArray ``` Produces a new array by calling a function on each element @@ -500,7 +504,7 @@ No other changes yet. ```grain -fromList : List -> ImmutableArray +fromList : (list: List) -> ImmutableArray ``` Converts the input list to an array. @@ -525,7 +529,7 @@ No other changes yet. ```grain -toList : ImmutableArray -> List +toList : (array: ImmutableArray) -> List ``` Converts the input array to a list. @@ -550,7 +554,7 @@ No other changes yet. ```grain -filter : ((a -> Bool), ImmutableArray) -> ImmutableArray +filter : (fn: (a -> Bool), array: ImmutableArray) -> ImmutableArray ``` Produces a new array by calling a function on each element of @@ -578,7 +582,7 @@ No other changes yet. ```grain -every : ((a -> Bool), ImmutableArray) -> Bool +every : (fn: (a -> Bool), array: ImmutableArray) -> Bool ``` Checks that the given condition is satisfied for all @@ -605,7 +609,7 @@ No other changes yet. ```grain -some : ((a -> Bool), ImmutableArray) -> Bool +some : (fn: (a -> Bool), array: ImmutableArray) -> Bool ``` Checks that the given condition is satisfied **at least @@ -632,7 +636,7 @@ No other changes yet. ```grain -reverse : ImmutableArray -> ImmutableArray +reverse : (array: ImmutableArray) -> ImmutableArray ``` Creates a new array with all elements in reverse order. @@ -657,7 +661,7 @@ No other changes yet. ```grain -contains : (a, ImmutableArray) -> Bool +contains : (value: a, array: ImmutableArray) -> Bool ``` Checks if the value is an element of the input array. @@ -684,7 +688,7 @@ No other changes yet. ```grain -find : ((a -> Bool), ImmutableArray) -> Option +find : (fn: (a -> Bool), array: ImmutableArray) -> Option ``` Finds the first element in an array that satifies the given condition. @@ -710,7 +714,7 @@ No other changes yet. ```grain -findIndex : ((a -> Bool), ImmutableArray) -> Option +findIndex : (fn: (a -> Bool), array: ImmutableArray) -> Option ``` Finds the first index in an array where the element satifies the given condition. @@ -736,7 +740,9 @@ No other changes yet. ```grain -product : (ImmutableArray, ImmutableArray) -> ImmutableArray<(a, b)> +product : + (array1: ImmutableArray, array2: ImmutableArray) -> + ImmutableArray<(a, b)> ``` Combines two arrays into a Cartesian product of tuples containing @@ -763,7 +769,7 @@ No other changes yet. ```grain -count : ((a -> Bool), ImmutableArray) -> Number +count : (fn: (a -> Bool), array: ImmutableArray) -> Number ``` Counts the number of elements in an array that satisfy the given condition. @@ -789,7 +795,7 @@ No other changes yet. ```grain -unique : ImmutableArray -> ImmutableArray +unique : (array: ImmutableArray) -> ImmutableArray ``` Produces a new array with any duplicates removed. @@ -815,7 +821,9 @@ No other changes yet. ```grain -zip : (ImmutableArray, ImmutableArray) -> ImmutableArray<(a, b)> +zip : + (array1: ImmutableArray, array2: ImmutableArray) -> + ImmutableArray<(a, b)> ``` Produces a new array filled with tuples of elements from both given arrays. @@ -847,7 +855,8 @@ No other changes yet. ```grain zipWith : - (((a, b) -> c), ImmutableArray, ImmutableArray) -> ImmutableArray + (fn: ((a, b) -> c), array1: ImmutableArray, array2: ImmutableArray) -> + ImmutableArray ``` Produces a new array filled with elements defined by applying a function on @@ -891,7 +900,8 @@ No other changes yet. ```grain -unzip : ImmutableArray<(a, b)> -> (ImmutableArray, ImmutableArray) +unzip : + (array: ImmutableArray<(a, b)>) -> (ImmutableArray, ImmutableArray) ``` Produces two arrays by splitting apart an array of tuples. @@ -916,7 +926,7 @@ No other changes yet. ```grain -join : (String, ImmutableArray) -> String +join : (separator: String, array: ImmutableArray) -> String ``` Concatenates an array of strings into a single string, separated by a separator string. @@ -942,7 +952,8 @@ No other changes yet. ```grain -slice : (Number, Number, ImmutableArray) -> ImmutableArray +slice : + (start: Number, end: Number, array: ImmutableArray) -> ImmutableArray ``` Slices an array given zero-based start and end indexes. The value @@ -983,7 +994,8 @@ No other changes yet. ```grain -sort : (((a, a) -> Number), ImmutableArray) -> ImmutableArray +sort : + (comp: ((a, a) -> Number), array: ImmutableArray) -> ImmutableArray ``` Sorts the given array based on a given comparator function. @@ -1011,7 +1023,7 @@ No other changes yet. ```grain -rotate : (Number, ImmutableArray) -> ImmutableArray +rotate : (n: Number, array: ImmutableArray) -> ImmutableArray ``` Rotates array elements by the specified amount to the left, such that the diff --git a/stdlib/immutablemap.md b/stdlib/immutablemap.md index 8b51684b55..2d4a529804 100644 --- a/stdlib/immutablemap.md +++ b/stdlib/immutablemap.md @@ -48,7 +48,7 @@ No other changes yet. ```grain -size : ImmutableMap -> Number +size : (map: ImmutableMap) -> Number ``` Provides the count of key-value pairs stored within the map. @@ -73,7 +73,7 @@ No other changes yet. ```grain -isEmpty : ImmutableMap -> Bool +isEmpty : (map: ImmutableMap) -> Bool ``` Determines if the map contains no key-value pairs. @@ -98,7 +98,7 @@ No other changes yet. ```grain -set : (a, b, ImmutableMap) -> ImmutableMap +set : (key: a, val: b, map: ImmutableMap) -> ImmutableMap ``` Produces a new map containing a new key-value pair. If the key already exists in the map, the value is replaced. @@ -125,7 +125,7 @@ No other changes yet. ```grain -get : (a, ImmutableMap) -> Option +get : (key: a, map: ImmutableMap) -> Option ``` Retrieves the value for the given key. @@ -151,7 +151,7 @@ No other changes yet. ```grain -contains : (a, ImmutableMap) -> Bool +contains : (key: a, map: ImmutableMap) -> Bool ``` Determines if the map contains the given key. In such a case, it will always contain a value for the given key. @@ -177,7 +177,7 @@ No other changes yet. ```grain -remove : (a, ImmutableMap) -> ImmutableMap +remove : (key: a, map: ImmutableMap) -> ImmutableMap ``` Produces a new map without the key-value pair corresponding to the given @@ -205,7 +205,8 @@ No other changes yet. ```grain update : - (a, (Option -> Option), ImmutableMap) -> ImmutableMap + (key: a, fn: (Option -> Option), map: ImmutableMap) -> + ImmutableMap ``` Produces a new map by calling an updater function that receives the @@ -236,7 +237,7 @@ No other changes yet. ```grain -forEach : (((a, b) -> Void), ImmutableMap) -> Void +forEach : (fn: ((a, b) -> Void), map: ImmutableMap) -> Void ``` Iterates the map, calling an iterator function with each key and value. @@ -256,7 +257,7 @@ No other changes yet. ```grain -reduce : (((a, b, c) -> a), a, ImmutableMap) -> a +reduce : (fn: ((a, b, c) -> a), init: a, map: ImmutableMap) -> a ``` Combines all key-value pairs of a map using a reducer function. @@ -283,7 +284,7 @@ No other changes yet. ```grain -keys : ImmutableMap -> List +keys : (map: ImmutableMap) -> List ``` Enumerates all keys in the given map. @@ -308,7 +309,7 @@ No other changes yet. ```grain -values : ImmutableMap -> List +values : (map: ImmutableMap) -> List ``` Enumerates all values in the given map. @@ -333,7 +334,8 @@ No other changes yet. ```grain -filter : (((a, b) -> Bool), ImmutableMap) -> ImmutableMap +filter : + (fn: ((a, b) -> Bool), map: ImmutableMap) -> ImmutableMap ``` Produces a new map excluding the key-value pairs where a predicate function returns `false`. @@ -359,7 +361,8 @@ No other changes yet. ```grain -reject : (((a, b) -> Bool), ImmutableMap) -> ImmutableMap +reject : + (fn: ((a, b) -> Bool), map: ImmutableMap) -> ImmutableMap ``` Produces a new map excluding the key-value pairs where a predicate function returns `true`. @@ -385,7 +388,7 @@ No other changes yet. ```grain -fromList : List<(a, b)> -> ImmutableMap +fromList : (list: List<(a, b)>) -> ImmutableMap ``` Creates a map from a list. @@ -410,7 +413,7 @@ No other changes yet. ```grain -toList : ImmutableMap -> List<(a, b)> +toList : (map: ImmutableMap) -> List<(a, b)> ``` Enumerates all key-value pairs in the given map. @@ -435,7 +438,7 @@ No other changes yet. ```grain -fromArray : Array<(a, b)> -> ImmutableMap +fromArray : (array: Array<(a, b)>) -> ImmutableMap ``` Creates a map from an array. @@ -460,7 +463,7 @@ No other changes yet. ```grain -toArray : ImmutableMap -> Array<(a, b)> +toArray : (map: ImmutableMap) -> Array<(a, b)> ``` Converts a map into an array of its key-value pairs. diff --git a/stdlib/immutablepriorityqueue.md b/stdlib/immutablepriorityqueue.md index a17d3f69da..2f4517af0b 100644 --- a/stdlib/immutablepriorityqueue.md +++ b/stdlib/immutablepriorityqueue.md @@ -50,7 +50,7 @@ No other changes yet. ```grain -make : ((a, a) -> Number) -> ImmutablePriorityQueue +make : (comp: ((a, a) -> Number)) -> ImmutablePriorityQueue ``` Creates a new priority queue with a comparator function, which is used to @@ -88,7 +88,7 @@ No other changes yet. ```grain -size : ImmutablePriorityQueue -> Number +size : (pq: ImmutablePriorityQueue) -> Number ``` Gets the number of elements in a priority queue. @@ -113,7 +113,7 @@ No other changes yet. ```grain -isEmpty : ImmutablePriorityQueue -> Bool +isEmpty : (pq: ImmutablePriorityQueue) -> Bool ``` Determines if the priority queue contains no elements. @@ -133,7 +133,7 @@ Returns: ### ImmutablePriorityQueue.**push** ```grain -push : (a, ImmutablePriorityQueue) -> ImmutablePriorityQueue +push : (val: a, pq: ImmutablePriorityQueue) -> ImmutablePriorityQueue ``` Produces a new priority queue by inserting the given element into the given priority queue. @@ -159,7 +159,7 @@ No other changes yet. ```grain -peek : ImmutablePriorityQueue -> Option +peek : (pq: ImmutablePriorityQueue) -> Option ``` Retrieves the highest priority element in the priority queue. It is not @@ -185,7 +185,7 @@ No other changes yet. ```grain -pop : ImmutablePriorityQueue -> ImmutablePriorityQueue +pop : (pq: ImmutablePriorityQueue) -> ImmutablePriorityQueue ``` Produces a new priority queue without the highest priority element in the @@ -212,7 +212,7 @@ No other changes yet. ```grain -drain : ImmutablePriorityQueue -> List +drain : (pq: ImmutablePriorityQueue) -> List ``` Produces a list of all elements in the priority queue in priority order. @@ -237,7 +237,8 @@ No other changes yet. ```grain -fromList : (List, ((a, a) -> Number)) -> ImmutablePriorityQueue +fromList : + (list: List, comp: ((a, a) -> Number)) -> ImmutablePriorityQueue ``` Constructs a new priority queue initialized with the elements in the list @@ -267,7 +268,8 @@ No other changes yet. ```grain -fromArray : (Array, ((a, a) -> Number)) -> ImmutablePriorityQueue +fromArray : + (array: Array, comp: ((a, a) -> Number)) -> ImmutablePriorityQueue ``` Constructs a new priority queue initialized with the elements in the array diff --git a/stdlib/immutableset.md b/stdlib/immutableset.md index dd49ecdc2d..869fbc27b4 100644 --- a/stdlib/immutableset.md +++ b/stdlib/immutableset.md @@ -48,7 +48,7 @@ No other changes yet. ```grain -size : ImmutableSet -> Number +size : (set: ImmutableSet) -> Number ``` Provides the count of values within the set. @@ -73,7 +73,7 @@ No other changes yet. ```grain -isEmpty : ImmutableSet -> Bool +isEmpty : (set: ImmutableSet) -> Bool ``` Determines if the set contains no elements. @@ -98,7 +98,7 @@ No other changes yet. ```grain -add : (a, ImmutableSet) -> ImmutableSet +add : (key: a, set: ImmutableSet) -> ImmutableSet ``` Produces a new set by inserting the given value into the set. If the value @@ -125,7 +125,7 @@ No other changes yet. ```grain -contains : (a, ImmutableSet) -> Bool +contains : (key: a, set: ImmutableSet) -> Bool ``` Determines if the set contains the given value. @@ -151,7 +151,7 @@ No other changes yet. ```grain -remove : (a, ImmutableSet) -> ImmutableSet +remove : (key: a, set: ImmutableSet) -> ImmutableSet ``` Produces a new set without the given element. If the value doesn't exist in @@ -178,7 +178,7 @@ No other changes yet. ```grain -forEach : ((a -> Void), ImmutableSet) -> Void +forEach : (fn: (a -> Void), set: ImmutableSet) -> Void ``` Iterates the set, calling an iterator function on each element. @@ -198,7 +198,7 @@ No other changes yet. ```grain -reduce : (((a, b) -> a), a, ImmutableSet) -> a +reduce : (fn: ((a, b) -> a), init: a, set: ImmutableSet) -> a ``` Combines all elements of a set using a reducer function. @@ -225,7 +225,7 @@ No other changes yet. ```grain -filter : ((a -> Bool), ImmutableSet) -> ImmutableSet +filter : (fn: (a -> Bool), set: ImmutableSet) -> ImmutableSet ``` Produces a new set without the elements from the input set where a predicate function returns `false`. @@ -251,7 +251,7 @@ No other changes yet. ```grain -reject : ((a -> Bool), ImmutableSet) -> ImmutableSet +reject : (fn: (a -> Bool), set: ImmutableSet) -> ImmutableSet ``` Produces a new set without the elements from the input set where a predicate function returns `true`. @@ -277,7 +277,7 @@ No other changes yet. ```grain -union : (ImmutableSet, ImmutableSet) -> ImmutableSet +union : (set1: ImmutableSet, set2: ImmutableSet) -> ImmutableSet ``` Combines two sets into a single set containing all elements from both sets. @@ -303,7 +303,7 @@ No other changes yet. ```grain -diff : (ImmutableSet, ImmutableSet) -> ImmutableSet +diff : (set1: ImmutableSet, set2: ImmutableSet) -> ImmutableSet ``` Combines two sets into a single set containing only the elements not shared between both sets. @@ -329,7 +329,7 @@ No other changes yet. ```grain -intersect : (ImmutableSet, ImmutableSet) -> ImmutableSet +intersect : (set1: ImmutableSet, set2: ImmutableSet) -> ImmutableSet ``` Combines two sets into a single set containing only the elements shared between both sets. @@ -355,7 +355,7 @@ No other changes yet. ```grain -fromList : List -> ImmutableSet +fromList : (list: List) -> ImmutableSet ``` Creates a set from a list. @@ -380,7 +380,7 @@ No other changes yet. ```grain -toList : ImmutableSet -> List +toList : (set: ImmutableSet) -> List ``` Converts a set into a list of its elements. @@ -405,7 +405,7 @@ No other changes yet. ```grain -fromArray : Array -> ImmutableSet +fromArray : (array: Array) -> ImmutableSet ``` Creates a set from an array. @@ -430,7 +430,7 @@ No other changes yet. ```grain -toArray : ImmutableSet -> Array +toArray : (set: ImmutableSet) -> Array ``` Converts a set into an array of its elements. diff --git a/stdlib/int16.md b/stdlib/int16.md index 85abdb9f79..7f3cd14f27 100644 --- a/stdlib/int16.md +++ b/stdlib/int16.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Int16 +fromNumber : (number: Number) -> Int16 ``` Converts a Number to an Int16. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Int16 -> Number +toNumber : (value: Int16) -> Number ``` Converts an Int16 to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -fromUint16 : Uint16 -> Int16 +fromUint16 : (x: Uint16) -> Int16 ``` Converts a Uint16 to an Int16. @@ -100,7 +100,7 @@ No other changes yet. ```grain -incr : Int16 -> Int16 +incr : (value: Int16) -> Int16 ``` Increments the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -decr : Int16 -> Int16 +decr : (value: Int16) -> Int16 ``` Decrements the value by one. @@ -150,7 +150,7 @@ No other changes yet. ```grain -(+) : (Int16, Int16) -> Int16 +(+) : (x: Int16, y: Int16) -> Int16 ``` Computes the sum of its operands. @@ -176,7 +176,7 @@ No other changes yet. ```grain -(-) : (Int16, Int16) -> Int16 +(-) : (x: Int16, y: Int16) -> Int16 ``` Computes the difference of its operands. @@ -202,7 +202,7 @@ No other changes yet. ```grain -(*) : (Int16, Int16) -> Int16 +(*) : (x: Int16, y: Int16) -> Int16 ``` Computes the product of its operands. @@ -228,7 +228,7 @@ No other changes yet. ```grain -(/) : (Int16, Int16) -> Int16 +(/) : (x: Int16, y: Int16) -> Int16 ``` Computes the quotient of its operands using signed division. @@ -254,7 +254,7 @@ No other changes yet. ```grain -rem : (Int16, Int16) -> Int16 +rem : (x: Int16, y: Int16) -> Int16 ``` Computes the remainder of the division of its operands using signed division. @@ -280,7 +280,7 @@ No other changes yet. ```grain -(%) : (Int16, Int16) -> Int16 +(%) : (x: Int16, y: Int16) -> Int16 ``` Computes the remainder of the division of the first operand by the second. @@ -313,7 +313,7 @@ No other changes yet. ```grain -(<<) : (Int16, Int16) -> Int16 +(<<) : (value: Int16, amount: Int16) -> Int16 ``` Shifts the bits of the value left by the given number of bits. @@ -339,7 +339,7 @@ No other changes yet. ```grain -(>>) : (Int16, Int16) -> Int16 +(>>) : (value: Int16, amount: Int16) -> Int16 ``` Shifts the bits of the value right by the given number of bits, preserving the sign bit. @@ -365,7 +365,7 @@ No other changes yet. ```grain -(==) : (Int16, Int16) -> Bool +(==) : (x: Int16, y: Int16) -> Bool ``` Checks if the first value is equal to the second value. @@ -391,7 +391,7 @@ No other changes yet. ```grain -(!=) : (Int16, Int16) -> Bool +(!=) : (x: Int16, y: Int16) -> Bool ``` Checks if the first value is not equal to the second value. @@ -417,7 +417,7 @@ No other changes yet. ```grain -(<) : (Int16, Int16) -> Bool +(<) : (x: Int16, y: Int16) -> Bool ``` Checks if the first value is less than the second value. @@ -443,7 +443,7 @@ No other changes yet. ```grain -(>) : (Int16, Int16) -> Bool +(>) : (x: Int16, y: Int16) -> Bool ``` Checks if the first value is greater than the second value. @@ -469,7 +469,7 @@ No other changes yet. ```grain -(<=) : (Int16, Int16) -> Bool +(<=) : (x: Int16, y: Int16) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -495,7 +495,7 @@ No other changes yet. ```grain -(>=) : (Int16, Int16) -> Bool +(>=) : (x: Int16, y: Int16) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -521,7 +521,7 @@ No other changes yet. ```grain -lnot : Int16 -> Int16 +lnot : (value: Int16) -> Int16 ``` Computes the bitwise NOT of the given value. @@ -546,7 +546,7 @@ No other changes yet. ```grain -(&) : (Int16, Int16) -> Int16 +(&) : (x: Int16, y: Int16) -> Int16 ``` Computes the bitwise AND (`&`) on the given operands. @@ -572,7 +572,7 @@ No other changes yet. ```grain -(|) : (Int16, Int16) -> Int16 +(|) : (x: Int16, y: Int16) -> Int16 ``` Computes the bitwise OR (`|`) on the given operands. @@ -598,7 +598,7 @@ No other changes yet. ```grain -(^) : (Int16, Int16) -> Int16 +(^) : (x: Int16, y: Int16) -> Int16 ``` Computes the bitwise XOR (`^`) on the given operands. diff --git a/stdlib/int32.md b/stdlib/int32.md index 15919e5efc..cf772dbe8c 100644 --- a/stdlib/int32.md +++ b/stdlib/int32.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Int32 +fromNumber : (x: Number) -> Int32 ``` Converts a Number to an Int32. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Int32 -> Number +toNumber : (x: Int32) -> Number ``` Converts an Int32 to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -fromUint32 : Uint32 -> Int32 +fromUint32 : (x: Uint32) -> Int32 ``` Converts a Uint32 to an Int32. @@ -100,7 +100,7 @@ No other changes yet. ```grain -incr : Int32 -> Int32 +incr : (value: Int32) -> Int32 ``` Increments the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -decr : Int32 -> Int32 +decr : (value: Int32) -> Int32 ``` Decrements the value by one. @@ -150,7 +150,7 @@ No other changes yet. ```grain -add : (Int32, Int32) -> Int32 +add : (x: Int32, y: Int32) -> Int32 ``` Computes the sum of its operands. @@ -176,7 +176,7 @@ No other changes yet. ```grain -sub : (Int32, Int32) -> Int32 +sub : (x: Int32, y: Int32) -> Int32 ``` Computes the difference of its operands. @@ -202,7 +202,7 @@ No other changes yet. ```grain -mul : (Int32, Int32) -> Int32 +mul : (x: Int32, y: Int32) -> Int32 ``` Computes the product of its operands. @@ -228,7 +228,7 @@ No other changes yet. ```grain -div : (Int32, Int32) -> Int32 +div : (x: Int32, y: Int32) -> Int32 ``` Computes the quotient of its operands using signed division. @@ -254,7 +254,7 @@ No other changes yet. ```grain -rem : (Int32, Int32) -> Int32 +rem : (x: Int32, y: Int32) -> Int32 ``` Computes the remainder of the division of its operands using signed division. @@ -280,7 +280,7 @@ No other changes yet. ```grain -mod : (Int32, Int32) -> Int32 +mod : (x: Int32, y: Int32) -> Int32 ``` Computes the remainder of the division of the first operand by the second. @@ -313,7 +313,7 @@ No other changes yet. ```grain -rotl : (Int32, Int32) -> Int32 +rotl : (value: Int32, amount: Int32) -> Int32 ``` Rotates the bits of the value left by the given number of bits. @@ -339,7 +339,7 @@ No other changes yet. ```grain -rotr : (Int32, Int32) -> Int32 +rotr : (value: Int32, amount: Int32) -> Int32 ``` Rotates the bits of the value right by the given number of bits. @@ -365,7 +365,7 @@ No other changes yet. ```grain -shl : (Int32, Int32) -> Int32 +shl : (value: Int32, amount: Int32) -> Int32 ``` Shifts the bits of the value left by the given number of bits. @@ -391,7 +391,7 @@ No other changes yet. ```grain -shr : (Int32, Int32) -> Int32 +shr : (value: Int32, amount: Int32) -> Int32 ``` Shifts the bits of the value right by the given number of bits, preserving the sign bit. @@ -417,7 +417,7 @@ No other changes yet. ```grain -eq : (Int32, Int32) -> Bool +eq : (x: Int32, y: Int32) -> Bool ``` Checks if the first value is equal to the second value. @@ -443,7 +443,7 @@ No other changes yet. ```grain -ne : (Int32, Int32) -> Bool +ne : (x: Int32, y: Int32) -> Bool ``` Checks if the first value is not equal to the second value. @@ -469,7 +469,7 @@ No other changes yet. ```grain -eqz : Int32 -> Bool +eqz : (value: Int32) -> Bool ``` Checks if the given value is equal to zero. @@ -494,7 +494,7 @@ No other changes yet. ```grain -lt : (Int32, Int32) -> Bool +lt : (x: Int32, y: Int32) -> Bool ``` Checks if the first value is less than the second value. @@ -520,7 +520,7 @@ No other changes yet. ```grain -gt : (Int32, Int32) -> Bool +gt : (x: Int32, y: Int32) -> Bool ``` Checks if the first value is greater than the second value. @@ -546,7 +546,7 @@ No other changes yet. ```grain -lte : (Int32, Int32) -> Bool +lte : (x: Int32, y: Int32) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -572,7 +572,7 @@ No other changes yet. ```grain -gte : (Int32, Int32) -> Bool +gte : (x: Int32, y: Int32) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -598,7 +598,7 @@ No other changes yet. ```grain -lnot : Int32 -> Int32 +lnot : (value: Int32) -> Int32 ``` Computes the bitwise NOT of the given value. @@ -623,7 +623,7 @@ No other changes yet. ```grain -land : (Int32, Int32) -> Int32 +land : (x: Int32, y: Int32) -> Int32 ``` Computes the bitwise AND (`&`) on the given operands. @@ -649,7 +649,7 @@ No other changes yet. ```grain -lor : (Int32, Int32) -> Int32 +lor : (x: Int32, y: Int32) -> Int32 ``` Computes the bitwise OR (`|`) on the given operands. @@ -675,7 +675,7 @@ No other changes yet. ```grain -lxor : (Int32, Int32) -> Int32 +lxor : (x: Int32, y: Int32) -> Int32 ``` Computes the bitwise XOR (`^`) on the given operands. @@ -701,7 +701,7 @@ No other changes yet. ```grain -clz : Int32 -> Int32 +clz : (value: Int32) -> Int32 ``` Counts the number of leading zero bits in the value. @@ -726,7 +726,7 @@ No other changes yet. ```grain -ctz : Int32 -> Int32 +ctz : (value: Int32) -> Int32 ``` Counts the number of trailing zero bits in the value. @@ -751,7 +751,7 @@ No other changes yet. ```grain -popcnt : Int32 -> Int32 +popcnt : (value: Int32) -> Int32 ``` Counts the number of bits set to `1` in the value, also known as a population count. diff --git a/stdlib/int64.md b/stdlib/int64.md index 7da72ad930..3fbb88b123 100644 --- a/stdlib/int64.md +++ b/stdlib/int64.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Int64 +fromNumber : (x: Number) -> Int64 ``` Converts a Number to an Int64. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Int64 -> Number +toNumber : (x: Int64) -> Number ``` Converts an Int64 to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -fromUint64 : Uint64 -> Int64 +fromUint64 : (x: Uint64) -> Int64 ``` Converts a Uint64 to an Int64. @@ -100,7 +100,7 @@ No other changes yet. ```grain -incr : Int64 -> Int64 +incr : (value: Int64) -> Int64 ``` Increments the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -decr : Int64 -> Int64 +decr : (value: Int64) -> Int64 ``` Decrements the value by one. @@ -150,7 +150,7 @@ No other changes yet. ```grain -add : (Int64, Int64) -> Int64 +add : (x: Int64, y: Int64) -> Int64 ``` Computes the sum of its operands. @@ -176,7 +176,7 @@ No other changes yet. ```grain -sub : (Int64, Int64) -> Int64 +sub : (x: Int64, y: Int64) -> Int64 ``` Computes the difference of its operands. @@ -202,7 +202,7 @@ No other changes yet. ```grain -mul : (Int64, Int64) -> Int64 +mul : (x: Int64, y: Int64) -> Int64 ``` Computes the product of its operands. @@ -228,7 +228,7 @@ No other changes yet. ```grain -div : (Int64, Int64) -> Int64 +div : (x: Int64, y: Int64) -> Int64 ``` Computes the quotient of its operands using signed division. @@ -254,7 +254,7 @@ No other changes yet. ```grain -rem : (Int64, Int64) -> Int64 +rem : (x: Int64, y: Int64) -> Int64 ``` Computes the remainder of the division of its operands using signed division. @@ -280,7 +280,7 @@ No other changes yet. ```grain -mod : (Int64, Int64) -> Int64 +mod : (x: Int64, y: Int64) -> Int64 ``` Computes the remainder of the division of the first operand by the second. @@ -313,7 +313,7 @@ No other changes yet. ```grain -rotl : (Int64, Int64) -> Int64 +rotl : (value: Int64, amount: Int64) -> Int64 ``` Rotates the bits of the value left by the given number of bits. @@ -339,7 +339,7 @@ No other changes yet. ```grain -rotr : (Int64, Int64) -> Int64 +rotr : (value: Int64, amount: Int64) -> Int64 ``` Rotates the bits of the value right by the given number of bits. @@ -365,7 +365,7 @@ No other changes yet. ```grain -shl : (Int64, Int64) -> Int64 +shl : (value: Int64, amount: Int64) -> Int64 ``` Shifts the bits of the value left by the given number of bits. @@ -391,7 +391,7 @@ No other changes yet. ```grain -shr : (Int64, Int64) -> Int64 +shr : (value: Int64, amount: Int64) -> Int64 ``` Shifts the bits of the value right by the given number of bits, preserving the sign bit. @@ -417,7 +417,7 @@ No other changes yet. ```grain -eq : (Int64, Int64) -> Bool +eq : (x: Int64, y: Int64) -> Bool ``` Checks if the first value is equal to the second value. @@ -443,7 +443,7 @@ No other changes yet. ```grain -ne : (Int64, Int64) -> Bool +ne : (x: Int64, y: Int64) -> Bool ``` Checks if the first value is not equal to the second value. @@ -469,7 +469,7 @@ No other changes yet. ```grain -eqz : Int64 -> Bool +eqz : (value: Int64) -> Bool ``` Checks if the given value is equal to zero. @@ -494,7 +494,7 @@ No other changes yet. ```grain -lt : (Int64, Int64) -> Bool +lt : (x: Int64, y: Int64) -> Bool ``` Checks if the first value is less than the second value. @@ -520,7 +520,7 @@ No other changes yet. ```grain -gt : (Int64, Int64) -> Bool +gt : (x: Int64, y: Int64) -> Bool ``` Checks if the first value is greater than the second value. @@ -546,7 +546,7 @@ No other changes yet. ```grain -lte : (Int64, Int64) -> Bool +lte : (x: Int64, y: Int64) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -572,7 +572,7 @@ No other changes yet. ```grain -gte : (Int64, Int64) -> Bool +gte : (x: Int64, y: Int64) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -598,7 +598,7 @@ No other changes yet. ```grain -lnot : Int64 -> Int64 +lnot : (value: Int64) -> Int64 ``` Computes the bitwise NOT of the given value. @@ -623,7 +623,7 @@ No other changes yet. ```grain -land : (Int64, Int64) -> Int64 +land : (x: Int64, y: Int64) -> Int64 ``` Computes the bitwise AND (`&`) on the given operands. @@ -649,7 +649,7 @@ No other changes yet. ```grain -lor : (Int64, Int64) -> Int64 +lor : (x: Int64, y: Int64) -> Int64 ``` Computes the bitwise OR (`|`) on the given operands. @@ -675,7 +675,7 @@ No other changes yet. ```grain -lxor : (Int64, Int64) -> Int64 +lxor : (x: Int64, y: Int64) -> Int64 ``` Computes the bitwise XOR (`^`) on the given operands. @@ -701,7 +701,7 @@ No other changes yet. ```grain -clz : Int64 -> Int64 +clz : (value: Int64) -> Int64 ``` Counts the number of leading zero bits in the value. @@ -726,7 +726,7 @@ No other changes yet. ```grain -ctz : Int64 -> Int64 +ctz : (value: Int64) -> Int64 ``` Counts the number of trailing zero bits in the value. @@ -751,7 +751,7 @@ No other changes yet. ```grain -popcnt : Int64 -> Int64 +popcnt : (value: Int64) -> Int64 ``` Counts the number of bits set to `1` in the value, also known as a population count. diff --git a/stdlib/int8.md b/stdlib/int8.md index e74023311f..223abb831b 100644 --- a/stdlib/int8.md +++ b/stdlib/int8.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Int8 +fromNumber : (number: Number) -> Int8 ``` Converts a Number to an Int8. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Int8 -> Number +toNumber : (value: Int8) -> Number ``` Converts an Int8 to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -fromUint8 : Uint8 -> Int8 +fromUint8 : (x: Uint8) -> Int8 ``` Converts a Uint8 to an Int8. @@ -100,7 +100,7 @@ No other changes yet. ```grain -incr : Int8 -> Int8 +incr : (value: Int8) -> Int8 ``` Increments the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -decr : Int8 -> Int8 +decr : (value: Int8) -> Int8 ``` Decrements the value by one. @@ -150,7 +150,7 @@ No other changes yet. ```grain -(+) : (Int8, Int8) -> Int8 +(+) : (x: Int8, y: Int8) -> Int8 ``` Computes the sum of its operands. @@ -176,7 +176,7 @@ No other changes yet. ```grain -(-) : (Int8, Int8) -> Int8 +(-) : (x: Int8, y: Int8) -> Int8 ``` Computes the difference of its operands. @@ -202,7 +202,7 @@ No other changes yet. ```grain -(*) : (Int8, Int8) -> Int8 +(*) : (x: Int8, y: Int8) -> Int8 ``` Computes the product of its operands. @@ -228,7 +228,7 @@ No other changes yet. ```grain -(/) : (Int8, Int8) -> Int8 +(/) : (x: Int8, y: Int8) -> Int8 ``` Computes the quotient of its operands using signed division. @@ -254,7 +254,7 @@ No other changes yet. ```grain -rem : (Int8, Int8) -> Int8 +rem : (x: Int8, y: Int8) -> Int8 ``` Computes the remainder of the division of its operands using signed division. @@ -280,7 +280,7 @@ No other changes yet. ```grain -(%) : (Int8, Int8) -> Int8 +(%) : (x: Int8, y: Int8) -> Int8 ``` Computes the remainder of the division of the first operand by the second. @@ -313,7 +313,7 @@ No other changes yet. ```grain -(<<) : (Int8, Int8) -> Int8 +(<<) : (value: Int8, amount: Int8) -> Int8 ``` Shifts the bits of the value left by the given number of bits. @@ -339,7 +339,7 @@ No other changes yet. ```grain -(>>) : (Int8, Int8) -> Int8 +(>>) : (value: Int8, amount: Int8) -> Int8 ``` Shifts the bits of the value right by the given number of bits, preserving the sign bit. @@ -365,7 +365,7 @@ No other changes yet. ```grain -(==) : (Int8, Int8) -> Bool +(==) : (x: Int8, y: Int8) -> Bool ``` Checks if the first value is equal to the second value. @@ -391,7 +391,7 @@ No other changes yet. ```grain -(!=) : (Int8, Int8) -> Bool +(!=) : (x: Int8, y: Int8) -> Bool ``` Checks if the first value is not equal to the second value. @@ -417,7 +417,7 @@ No other changes yet. ```grain -(<) : (Int8, Int8) -> Bool +(<) : (x: Int8, y: Int8) -> Bool ``` Checks if the first value is less than the second value. @@ -443,7 +443,7 @@ No other changes yet. ```grain -(>) : (Int8, Int8) -> Bool +(>) : (x: Int8, y: Int8) -> Bool ``` Checks if the first value is greater than the second value. @@ -469,7 +469,7 @@ No other changes yet. ```grain -(<=) : (Int8, Int8) -> Bool +(<=) : (x: Int8, y: Int8) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -495,7 +495,7 @@ No other changes yet. ```grain -(>=) : (Int8, Int8) -> Bool +(>=) : (x: Int8, y: Int8) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -521,7 +521,7 @@ No other changes yet. ```grain -lnot : Int8 -> Int8 +lnot : (value: Int8) -> Int8 ``` Computes the bitwise NOT of the given value. @@ -546,7 +546,7 @@ No other changes yet. ```grain -(&) : (Int8, Int8) -> Int8 +(&) : (x: Int8, y: Int8) -> Int8 ``` Computes the bitwise AND (`&`) on the given operands. @@ -572,7 +572,7 @@ No other changes yet. ```grain -(|) : (Int8, Int8) -> Int8 +(|) : (x: Int8, y: Int8) -> Int8 ``` Computes the bitwise OR (`|`) on the given operands. @@ -598,7 +598,7 @@ No other changes yet. ```grain -(^) : (Int8, Int8) -> Int8 +(^) : (x: Int8, y: Int8) -> Int8 ``` Computes the bitwise XOR (`^`) on the given operands. diff --git a/stdlib/list.md b/stdlib/list.md index bbc4d4b214..1b48708011 100644 --- a/stdlib/list.md +++ b/stdlib/list.md @@ -33,7 +33,7 @@ No other changes yet. ```grain -init : (Number, (Number -> a)) -> List +init : (length: Number, fn: (Number -> a)) -> List ``` Creates a new list of the specified length where each element is @@ -74,7 +74,7 @@ List.init(5, n => n + 3) // [3, 4, 5, 6, 7] ```grain -length : List -> Number +length : (list: List) -> Number ``` Computes the length of the input list. @@ -99,7 +99,7 @@ No other changes yet. ```grain -reverse : List -> List +reverse : (list: List) -> List ``` Creates a new list with all elements in reverse order. @@ -124,7 +124,7 @@ No other changes yet. ```grain -append : (List, List) -> List +append : (list1: List, list2: List) -> List ``` Creates a new list with the elements of the first list followed by @@ -151,7 +151,7 @@ No other changes yet. ```grain -contains : (a, List) -> Bool +contains : (search: a, list: List) -> Bool ``` Checks if the value is an element of the input list. @@ -186,7 +186,7 @@ Returns: ```grain -reduce : (((a, b) -> a), a, List) -> a +reduce : (fn: ((a, b) -> a), initial: a, list: List) -> a ``` Combines all elements of a list using a reducer function, @@ -233,7 +233,7 @@ List.reduce((a, b) => a + b, 0, [1, 2, 3]) // 6 ```grain -reduceRight : (((a, b) -> b), b, List) -> b +reduceRight : (fn: ((a, b) -> b), initial: b, list: List) -> b ``` Combines all elements of a list using a reducer function, @@ -272,7 +272,7 @@ No other changes yet. ```grain -map : ((a -> b), List) -> List +map : (fn: (a -> b), list: List) -> List ``` Produces a new list initialized with the results of a mapper function @@ -299,7 +299,7 @@ No other changes yet. ```grain -mapi : (((a, Number) -> b), List) -> List +mapi : (fn: ((a, Number) -> b), list: List) -> List ``` Produces a new list initialized with the results of a mapper function @@ -326,7 +326,7 @@ No other changes yet. ```grain -flatMap : ((a -> List), List) -> List +flatMap : (fn: (a -> List), list: List) -> List ``` Produces a new list by calling a function on each element @@ -355,7 +355,7 @@ No other changes yet. ```grain -every : ((a -> Bool), List) -> Bool +every : (fn: (a -> Bool), list: List) -> Bool ``` Checks that the given condition is satisfied for all @@ -382,7 +382,7 @@ No other changes yet. ```grain -some : ((a -> Bool), List) -> Bool +some : (fn: (a -> Bool), list: List) -> Bool ``` Checks that the given condition is satisfied **at least @@ -409,7 +409,7 @@ No other changes yet. ```grain -forEach : ((a -> Void), List) -> Void +forEach : (fn: (a -> Void), list: List) -> Void ``` Iterates a list, calling an iterator function on each element. @@ -429,7 +429,7 @@ No other changes yet. ```grain -forEachi : (((a, Number) -> Void), List) -> Void +forEachi : (fn: ((a, Number) -> Void), list: List) -> Void ``` Iterates a list, calling an iterator function on each element. @@ -450,7 +450,7 @@ No other changes yet. ```grain -filter : ((a -> Bool), List) -> List +filter : (fn: (a -> Bool), list: List) -> List ``` Produces a new list by calling a function on each element of @@ -478,7 +478,7 @@ No other changes yet. ```grain -filteri : (((a, Number) -> Bool), List) -> List +filteri : (fn: ((a, Number) -> Bool), list: List) -> List ``` Produces a new list by calling a function on each element of @@ -506,7 +506,7 @@ No other changes yet. ```grain -reject : ((a -> Bool), List) -> List +reject : (fn: (a -> Bool), list: List) -> List ``` Produces a new list by calling a function on each element of @@ -543,7 +543,7 @@ Returns: ```grain -head : List -> Option +head : (list: List) -> Option ``` Provides `Some(element)` containing the first element, or "head", of @@ -578,7 +578,7 @@ Returns: ```grain -tail : List -> Option> +tail : (list: List) -> Option> ``` Provides `Some(tail)` containing all list items except the first element, or "tail", of @@ -612,7 +612,7 @@ Returns: ```grain -nth : (Number, List) -> Option +nth : (index: Number, list: List) -> Option ``` Provides `Some(element)` containing the element in the list at the specified index @@ -639,7 +639,7 @@ No other changes yet. ```grain -flatten : List> -> List +flatten : (list: List>) -> List ``` Flattens nested lists. @@ -670,7 +670,7 @@ No other changes yet. ```grain -insert : (a, Number, List) -> List +insert : (value: a, index: Number, list: List) -> List ``` Inserts a new value into a list at the specified index. @@ -711,7 +711,7 @@ Throws: ```grain -count : ((a -> Bool), List) -> Number +count : (fn: (a -> Bool), list: List) -> Number ``` Counts the number of elements in a list that satisfy the given condition. @@ -737,7 +737,7 @@ No other changes yet. ```grain -part : (Number, List) -> (List, List) +part : (count: Number, list: List) -> (List, List) ``` Split a list into two, with the first list containing the required number of elements. @@ -777,7 +777,7 @@ Throws: ```grain -rotate : (Number, List) -> List +rotate : (count: Number, list: List) -> List ``` Rotates list elements by the specified amount to the left, such that `n`th @@ -823,7 +823,7 @@ List.rotate(-7, [1, 2, 3, 4, 5]) // [4, 5, 1, 2, 3] ```grain -unique : List -> List +unique : (list: List) -> List ``` Produces a new list with any duplicates removed. @@ -849,7 +849,7 @@ No other changes yet. ```grain -zip : (List, List) -> List<(a, b)> +zip : (list1: List, list2: List) -> List<(a, b)> ``` Produces a new list filled with tuples of elements from both given lists. @@ -890,7 +890,7 @@ No other changes yet. ```grain -zipWith : (((a, b) -> c), List, List) -> List +zipWith : (fn: ((a, b) -> c), list1: List, list2: List) -> List ``` Produces a new list filled with elements defined by applying a function on @@ -934,7 +934,7 @@ No other changes yet. ```grain -unzip : List<(a, b)> -> (List, List) +unzip : (list: List<(a, b)>) -> (List, List) ``` Produces two lists by splitting apart a list of tuples. @@ -959,7 +959,7 @@ No other changes yet. ```grain -drop : (Number, List) -> List +drop : (count: Number, list: List) -> List ``` Produces a new list with the specified number of elements removed from @@ -992,7 +992,7 @@ No other changes yet. ```grain -dropWhile : ((a -> Bool), List) -> List +dropWhile : (fn: (a -> Bool), list: List) -> List ``` Produces a new list with the elements removed from the beginning @@ -1020,7 +1020,7 @@ No other changes yet. ```grain -take : (Number, List) -> List +take : (count: Number, list: List) -> List ``` Produces a new list with–at most—the specified amount elements from @@ -1053,7 +1053,7 @@ No other changes yet. ```grain -takeWhile : ((a -> Bool), List) -> List +takeWhile : (fn: (a -> Bool), list: List) -> List ``` Produces a new list with elements from the beginning of the input list @@ -1089,7 +1089,7 @@ Returns: ```grain -find : ((a -> Bool), List) -> Option +find : (fn: (a -> Bool), list: List) -> Option ``` Finds the first element in a list that satifies the given condition. @@ -1123,7 +1123,7 @@ Returns: ```grain -findIndex : ((a -> Bool), List) -> Option +findIndex : (fn: (a -> Bool), list: List) -> Option ``` Finds the first index in a list where the element satifies the given condition. @@ -1149,7 +1149,7 @@ No other changes yet. ```grain -product : (List, List) -> List<(a, b)> +product : (list1: List, list2: List) -> List<(a, b)> ``` Combines two lists into a Cartesian product of tuples containing @@ -1176,7 +1176,7 @@ No other changes yet. ```grain -sub : (Number, Number, List) -> List +sub : (start: Number, length: Number, list: List) -> List ``` Provides the subset of a list given zero-based start index and amount of elements @@ -1211,7 +1211,7 @@ No other changes yet. ```grain -join : (String, List) -> String +join : (separator: String, list: List) -> String ``` Combine the given list of strings into one string with the specified @@ -1238,7 +1238,7 @@ No other changes yet. ```grain -revAppend : (List, List) -> List +revAppend : (list1: List, list2: List) -> List ``` Reverses the first list and appends the second list to the end. @@ -1264,7 +1264,7 @@ No other changes yet. ```grain -sort : (((a, a) -> Number), List) -> List +sort : (comp: ((a, a) -> Number), list: List) -> List ``` Sorts the given list based on a given comparator function. The resulting list is sorted in increasing order. diff --git a/stdlib/map.md b/stdlib/map.md index 88116f9d6a..7c4e1329f8 100644 --- a/stdlib/map.md +++ b/stdlib/map.md @@ -35,7 +35,7 @@ No other changes yet. ```grain -makeSized : Number -> Map +makeSized : (size: Number) -> Map ``` Creates a new empty map with an initial storage of the given size. As values are added or removed, the internal storage may grow or shrink. Generally, you won't need to care about the storage size of your map and can use `Map.make()` instead. @@ -79,7 +79,7 @@ No other changes yet. ```grain -set : (a, b, Map) -> Void +set : (key: a, value: b, map: Map) -> Void ``` Adds a new key-value pair to the map. If the key already exists in the map, the value is replaced. @@ -100,7 +100,7 @@ No other changes yet. ```grain -get : (a, Map) -> Option +get : (key: a, map: Map) -> Option ``` Retrieves the value for the given key. @@ -126,7 +126,7 @@ No other changes yet. ```grain -contains : (a, Map) -> Bool +contains : (key: a, map: Map) -> Bool ``` Determines if the map contains the given key. In such a case, it will always contain a value for the given key. @@ -152,7 +152,7 @@ No other changes yet. ```grain -remove : (a, Map) -> Void +remove : (key: a, map: Map) -> Void ``` Removes the given key from the map, which also removes the value. If the key pair doesn't exist, nothing happens. @@ -172,7 +172,7 @@ No other changes yet. ```grain -update : (a, (Option -> Option), Map) -> Void +update : (key: a, fn: (Option -> Option), map: Map) -> Void ``` Updates a value in the map by calling an updater function that receives the previously stored value as an `Option` and returns the new value to be stored as an `Option`. If the key didn't exist previously, the value will be `None`. If `None` is returned from the updater function, the key-value pair is removed. @@ -193,7 +193,7 @@ No other changes yet. ```grain -size : Map -> Number +size : (map: Map) -> Number ``` Provides the count of key-value pairs stored within the map. @@ -218,7 +218,7 @@ No other changes yet. ```grain -isEmpty : Map -> Bool +isEmpty : (map: Map) -> Bool ``` Determines if the map contains no key-value pairs. @@ -243,7 +243,7 @@ No other changes yet. ```grain -clear : Map -> Void +clear : (map: Map) -> Void ``` Resets the map by removing all key-value pairs. @@ -269,7 +269,7 @@ Parameters: ```grain -forEach : (((a, b) -> Void), Map) -> Void +forEach : (fn: ((a, b) -> Void), map: Map) -> Void ``` Iterates the map, calling an iterator function with each key and value. @@ -289,7 +289,7 @@ No other changes yet. ```grain -reduce : (((a, b, c) -> a), a, Map) -> a +reduce : (fn: ((a, b, c) -> a), init: a, map: Map) -> a ``` Combines all key-value pairs of a map using a reducer function. @@ -316,7 +316,7 @@ No other changes yet. ```grain -keys : Map -> List +keys : (map: Map) -> List ``` Enumerates all keys in the given map. @@ -341,7 +341,7 @@ No other changes yet. ```grain -values : Map -> List +values : (map: Map) -> List ``` Enumerates all values in the given map. @@ -366,7 +366,7 @@ No other changes yet. ```grain -toList : Map -> List<(a, b)> +toList : (map: Map) -> List<(a, b)> ``` Enumerates all key-value pairs in the given map. @@ -391,7 +391,7 @@ No other changes yet. ```grain -fromList : List<(a, b)> -> Map +fromList : (list: List<(a, b)>) -> Map ``` Creates a map from a list. @@ -441,7 +441,7 @@ No other changes yet. ```grain -fromArray : Array<(a, b)> -> Map +fromArray : (array: Array<(a, b)>) -> Map ``` Creates a map from an array. @@ -466,7 +466,7 @@ No other changes yet. ```grain -filter : (((a, b) -> Bool), Map) -> Void +filter : (predicate: ((a, b) -> Bool), map: Map) -> Void ``` Removes key-value pairs from a map where a predicate function returns `false`. @@ -486,7 +486,7 @@ No other changes yet. ```grain -reject : (((a, b) -> Bool), Map) -> Void +reject : (predicate: ((a, b) -> Bool), map: Map) -> Void ``` Removes key-value pairs from a map where a predicate function returns `true`. @@ -506,7 +506,7 @@ No other changes yet. ```grain -getInternalStats : Map -> (Number, Number) +getInternalStats : (map: Map) -> (Number, Number) ``` Provides data representing the internal state state of the map. diff --git a/stdlib/marshal.md b/stdlib/marshal.md index a05cedae70..86f1d836a4 100644 --- a/stdlib/marshal.md +++ b/stdlib/marshal.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -marshal : a -> Bytes +marshal : (value: a) -> Bytes ``` Serialize a value into a byte-based representation suitable for transmission @@ -52,7 +52,7 @@ No other changes yet. ```grain -unmarshal : Bytes -> Result +unmarshal : (bytes: Bytes) -> Result ``` Deserialize the byte-based representation of a value back into an in-memory diff --git a/stdlib/number.md b/stdlib/number.md index eedb2499f5..d96e63b26b 100644 --- a/stdlib/number.md +++ b/stdlib/number.md @@ -71,7 +71,7 @@ Euler's number represented as a Number value. ```grain -(+) : (Number, Number) -> Number +(+) : (x: Number, y: Number) -> Number ``` Computes the sum of its operands. @@ -104,7 +104,7 @@ Returns: ```grain -(-) : (Number, Number) -> Number +(-) : (x: Number, y: Number) -> Number ``` Computes the difference of its operands. @@ -137,7 +137,7 @@ Returns: ```grain -(*) : (Number, Number) -> Number +(*) : (x: Number, y: Number) -> Number ``` Computes the product of its operands. @@ -170,7 +170,7 @@ Returns: ```grain -(/) : (Number, Number) -> Number +(/) : (x: Number, y: Number) -> Number ``` Computes the quotient of its operands. @@ -203,7 +203,7 @@ Returns: ```grain -(**) : (Number, Number) -> Number +(**) : (base: Number, power: Number) -> Number ``` Computes the exponentiation of the given base and power. @@ -229,7 +229,7 @@ No other changes yet. ```grain -exp : Number -> Number +exp : (power: Number) -> Number ``` Computes the exponentiation of Euler's number to the given power. @@ -254,7 +254,7 @@ No other changes yet. ```grain -sqrt : Number -> Number +sqrt : (x: Number) -> Number ``` Computes the square root of its operand. @@ -274,7 +274,7 @@ Returns: ### Number.**sign** ```grain -sign : Number -> Number +sign : (x: Number) -> Number ``` Determine the positivity or negativity of a Number. @@ -320,7 +320,7 @@ Number.sign(0) == 0 ```grain -min : (Number, Number) -> Number +min : (x: Number, y: Number) -> Number ``` Returns the smaller of its operands. @@ -353,7 +353,7 @@ Returns: ```grain -max : (Number, Number) -> Number +max : (x: Number, y: Number) -> Number ``` Returns the larger of its operands. @@ -386,7 +386,7 @@ Returns: ```grain -ceil : Number -> Number +ceil : (x: Number) -> Number ``` Rounds its operand up to the next largest integer. @@ -418,7 +418,7 @@ Returns: ```grain -floor : Number -> Number +floor : (x: Number) -> Number ``` Rounds its operand down to the largest integer less than the operand. @@ -450,7 +450,7 @@ Returns: ```grain -trunc : Number -> Number +trunc : (x: Number) -> Number ``` Returns the integer part of its operand, removing any fractional value. @@ -482,7 +482,7 @@ Returns: ```grain -round : Number -> Number +round : (x: Number) -> Number ``` Returns its operand rounded to its nearest integer. @@ -507,7 +507,7 @@ No other changes yet. ```grain -abs : Number -> Number +abs : (x: Number) -> Number ``` Returns the absolute value of a number. That is, it returns `x` if `x` is positive or zero and the negation of `x` if `x` is negative. @@ -532,7 +532,7 @@ No other changes yet. ```grain -neg : Number -> Number +neg : (x: Number) -> Number ``` Returns the negation of its operand. @@ -557,7 +557,7 @@ No other changes yet. ```grain -isFloat : Number -> Bool +isFloat : (x: Number) -> Bool ``` Checks if a number is a floating point value. @@ -582,7 +582,7 @@ No other changes yet. ```grain -isInteger : Number -> Bool +isInteger : (x: Number) -> Bool ``` Checks if a number is an integer. @@ -607,7 +607,7 @@ No other changes yet. ```grain -isRational : Number -> Bool +isRational : (x: Number) -> Bool ``` Checks if a number is a non-integer rational value. @@ -632,7 +632,7 @@ No other changes yet. ```grain -isFinite : Number -> Bool +isFinite : (x: Number) -> Bool ``` Checks if a number is finite. @@ -658,7 +658,7 @@ No other changes yet. ```grain -isNaN : Number -> Bool +isNaN : (x: Number) -> Bool ``` Checks if a number is the float NaN value (Not A Number). @@ -683,7 +683,7 @@ No other changes yet. ```grain -isInfinite : Number -> Bool +isInfinite : (x: Number) -> Bool ``` Checks if a number is infinite, that is either of floating point positive or negative infinity. @@ -709,7 +709,7 @@ No other changes yet. ```grain -parseInt : (String, Number) -> Result +parseInt : (string: String, radix: Number) -> Result ``` Parses a string representation of an integer into a `Number` using the @@ -741,7 +741,7 @@ No other changes yet. ```grain -parseFloat : String -> Result +parseFloat : (string: String) -> Result ``` Parses a string representation of a float into a `Number`. Underscores that appear @@ -767,7 +767,7 @@ No other changes yet. ```grain -parse : String -> Result +parse : (input: String) -> Result ``` Parses a string representation of an integer, float, or rational into a `Number`. @@ -800,7 +800,7 @@ Returns: ```grain -sin : Number -> Number +sin : (radians: Number) -> Number ``` Computes the sine of a number (in radians) using Chebyshev polynomials. @@ -832,7 +832,7 @@ Returns: ```grain -cos : Number -> Number +cos : (radians: Number) -> Number ``` Computes the cosine of a number (in radians) using Chebyshev polynomials. @@ -857,7 +857,7 @@ No other changes yet. ```grain -tan : Number -> Number +tan : (radians: Number) -> Number ``` Computes the tangent of a number (in radians) using Chebyshev polynomials. @@ -882,7 +882,7 @@ No other changes yet. ```grain -gamma : Number -> Number +gamma : (z: Number) -> Number ``` Computes the gamma function of a value using Lanczos approximation. @@ -913,7 +913,7 @@ No other changes yet. ```grain -factorial : Number -> Number +factorial : (n: Number) -> Number ``` Computes the product of consecutive integers for an integer input and computes the gamma function for non-integer inputs. @@ -944,7 +944,7 @@ No other changes yet. ```grain -toRadians : Number -> Number +toRadians : (degrees: Number) -> Number ``` Converts degrees to radians. @@ -969,7 +969,7 @@ No other changes yet. ```grain -toDegrees : Number -> Number +toDegrees : (radians: Number) -> Number ``` Converts radians to degrees. diff --git a/stdlib/option.md b/stdlib/option.md index dd655b8337..97c12b97ca 100644 --- a/stdlib/option.md +++ b/stdlib/option.md @@ -35,7 +35,7 @@ No other changes yet. ```grain -isSome : Option -> Bool +isSome : (option: Option) -> Bool ``` Checks if the Option is the `Some` variant. @@ -60,7 +60,7 @@ No other changes yet. ```grain -isNone : Option -> Bool +isNone : (option: Option) -> Bool ``` Checks if the Option is the `None` variant. @@ -85,7 +85,7 @@ No other changes yet. ```grain -contains : (a, Option) -> Bool +contains : (value: a, option: Option) -> Bool ``` Checks if the Option is the `Some` variant and contains the given value. Uses the generic `==` equality operator. @@ -111,7 +111,7 @@ No other changes yet. ```grain -expect : (String, Option) -> a +expect : (msg: String, option: Option) -> a ``` Extracts the value inside a `Some` option, otherwise throws an @@ -144,7 +144,7 @@ No other changes yet. ```grain -unwrap : Option -> a +unwrap : (option: Option) -> a ``` Extracts the value inside a `Some` option, otherwise @@ -176,7 +176,7 @@ No other changes yet. ```grain -unwrapWithDefault : (a, Option) -> a +unwrapWithDefault : (default: a, option: Option) -> a ``` Extracts the value inside a `Some` option or provide the default value if `None`. @@ -202,7 +202,7 @@ No other changes yet. ```grain -map : ((a -> b), Option) -> Option +map : (fn: (a -> b), option: Option) -> Option ``` If the Option is `Some(value)`, applies the given function to the `value` and wraps the new value in a `Some` variant. @@ -228,7 +228,7 @@ No other changes yet. ```grain -mapWithDefault : ((a -> b), b, Option) -> b +mapWithDefault : (fn: (a -> b), default: b, option: Option) -> b ``` If the Option is `Some(value)`, applies the given function to the `value` to produce a new value, otherwise uses the default value. @@ -256,7 +256,8 @@ No other changes yet. ```grain -mapWithDefaultFn : ((a -> b), (() -> b), Option) -> b +mapWithDefaultFn : + (fn: (a -> b), defaultFn: (() -> b), option: Option) -> b ``` If the Option is `Some(value)`, applies the `fn` function to the `value` to produce a new value. @@ -285,7 +286,7 @@ No other changes yet. ```grain -flatMap : ((a -> Option), Option) -> Option +flatMap : (fn: (a -> Option), option: Option) -> Option ``` If the Option is `Some(value)`, applies the given function to the `value` to produce a new Option. @@ -311,7 +312,7 @@ No other changes yet. ```grain -filter : ((a -> Bool), Option) -> Option +filter : (fn: (a -> Bool), option: Option) -> Option ``` Converts `Some(value)` variants to `None` variants where the predicate function returns `false`. @@ -338,7 +339,7 @@ No other changes yet. ```grain -zip : (Option, Option) -> Option<(a, b)> +zip : (optionA: Option, optionB: Option) -> Option<(a, b)> ``` Combine two Options into a single Option containing a tuple of their values. @@ -364,7 +365,8 @@ No other changes yet. ```grain -zipWith : (((a, b) -> c), Option, Option) -> Option +zipWith : + (fn: ((a, b) -> c), optionA: Option, optionB: Option) -> Option ``` Combine two Options into a single Option. The new value is produced by applying the given function to both values. @@ -391,7 +393,7 @@ No other changes yet. ```grain -flatten : Option> -> Option +flatten : (option: Option>) -> Option ``` Flattens nested Options. @@ -422,7 +424,7 @@ No other changes yet. ```grain -toList : Option -> List +toList : (option: Option) -> List ``` Converts an Option to a list with either zero or one item. @@ -447,7 +449,7 @@ No other changes yet. ```grain -toArray : Option -> Array +toArray : (option: Option) -> Array ``` Converts an Option to an array with either zero or one item. @@ -472,7 +474,7 @@ No other changes yet. ```grain -toResult : (a, Option) -> Result +toResult : (err: a, option: Option) -> Result ``` Converts the Option to a Result, using the provided error in case of the `None` variant. @@ -498,7 +500,7 @@ No other changes yet. ```grain -sideEffect : ((a -> Void), Option) -> Void +sideEffect : (fn: (a -> Void), option: Option) -> Void ``` If the Option is `Some(value)`, applies the `fn` function to the `value` without producing a new value. @@ -518,7 +520,7 @@ No other changes yet. ```grain -peek : ((a -> Void), Option) -> Option +peek : (fn: (a -> Void), option: Option) -> Option ``` If the Option is `Some(value)`, applies the `fn` function to the `value` without producing a new value. @@ -545,7 +547,7 @@ No other changes yet. ```grain -or : (Option, Option) -> Option +or : (optionA: Option, optionB: Option) -> Option ``` Behaves like a logical OR (`||`) where the first Option is only returned if it is the `Some` variant and falling back to the second Option in all other cases. @@ -571,7 +573,7 @@ No other changes yet. ```grain -and : (Option, Option) -> Option +and : (optionA: Option, optionB: Option) -> Option ``` Behaves like a logical AND (`&&`) where the first Option is only returned if it is the `None` variant and falling back to the second Option Result in all other cases. diff --git a/stdlib/path.md b/stdlib/path.md index 3897bbe096..57963eb862 100644 --- a/stdlib/path.md +++ b/stdlib/path.md @@ -177,7 +177,7 @@ No other changes yet. ```grain -fromString : String -> Path +fromString : (pathStr: String) -> Path ``` Parses a path string into a `Path`. Paths will be parsed as file paths @@ -217,7 +217,7 @@ No other changes yet. ```grain -fromPlatformString : (String, Platform) -> Path +fromPlatformString : (pathStr: String, platform: Platform) -> Path ``` Parses a path string into a `Path` using the path separators appropriate to @@ -256,7 +256,7 @@ No other changes yet. ```grain -toString : Path -> String +toString : (path: Path) -> String ``` Converts the given `Path` into a string, using the `/` path separator. @@ -292,7 +292,7 @@ No other changes yet. ```grain -toPlatformString : (Path, Platform) -> String +toPlatformString : (path: Path, platform: Platform) -> String ``` Converts the given `Path` into a string, using the canonical path separator @@ -330,7 +330,7 @@ No other changes yet. ```grain -isDirectory : Path -> Bool +isDirectory : (path: Path) -> Bool ``` Determines whether the path is a directory path. @@ -360,7 +360,7 @@ isDirectory(fromString("/bin/")) == true ### Path.**isAbsolute** ```grain -isAbsolute : Path -> Bool +isAbsolute : (path: Path) -> Bool ``` Determines whether the path is an absolute path. @@ -395,7 +395,7 @@ No other changes yet. ```grain -append : (Path, Path) -> Result +append : (path: Path, toAppend: Path) -> Result ``` Creates a new path by appending a relative path segment to a directory path. @@ -435,7 +435,7 @@ No other changes yet. ```grain -relativeTo : (Path, Path) -> Result +relativeTo : (source: Path, dest: Path) -> Result ``` Attempts to construct a new relative path which will lead to the destination @@ -494,7 +494,8 @@ No other changes yet. ```grain -ancestry : (Path, Path) -> Result +ancestry : + (path1: Path, path2: Path) -> Result ``` Determines the relative ancestry betwen two paths. @@ -538,7 +539,7 @@ No other changes yet. ```grain -parent : Path -> Path +parent : (path: Path) -> Path ``` Retrieves the path corresponding to the parent directory of the given path. @@ -573,7 +574,7 @@ No other changes yet. ```grain -basename : Path -> Option +basename : (path: Path) -> Option ``` Retrieves the basename (named final segment) of a path. @@ -608,7 +609,7 @@ No other changes yet. ```grain -stem : Path -> Result +stem : (path: Path) -> Result ``` Retrieves the basename of a file path without the extension. @@ -651,7 +652,7 @@ No other changes yet. ```grain -extension : Path -> Result +extension : (path: Path) -> Result ``` Retrieves the extension on the basename of a file path. @@ -694,7 +695,7 @@ No other changes yet. ```grain -root : Path -> Result +root : (path: Path) -> Result ``` Retrieves the root of the absolute path. diff --git a/stdlib/pervasives.md b/stdlib/pervasives.md index 0ad5e7636d..201fe33583 100644 --- a/stdlib/pervasives.md +++ b/stdlib/pervasives.md @@ -119,7 +119,7 @@ No other changes yet. ```grain -(==) : (a, a) -> Bool +(==) : (x: a, y: a) -> Bool ``` Check that two values are equal. This checks for structural equality, @@ -227,7 +227,7 @@ No other changes yet. ```grain -(<) : (Number, Number) -> Bool +(<) : (x: Number, y: Number) -> Bool ``` Checks if the first operand is less than the second operand. @@ -253,7 +253,7 @@ No other changes yet. ```grain -(>) : (Number, Number) -> Bool +(>) : (x: Number, y: Number) -> Bool ``` Checks if the first operand is greater than the second operand. @@ -279,7 +279,7 @@ No other changes yet. ```grain -(<=) : (Number, Number) -> Bool +(<=) : (x: Number, y: Number) -> Bool ``` Checks if the first operand is less than or equal to the second operand. @@ -305,7 +305,7 @@ No other changes yet. ```grain -(>=) : (Number, Number) -> Bool +(>=) : (x: Number, y: Number) -> Bool ``` Checks if the first operand is greater than or equal to the second operand. @@ -331,7 +331,7 @@ No other changes yet. ```grain -compare : (a, a) -> Number +compare : (x: a, y: a) -> Number ``` Compares the first argument to the second argument and produces an integer result. @@ -359,7 +359,7 @@ No other changes yet. ```grain -(+) : (Number, Number) -> Number +(+) : (x: Number, y: Number) -> Number ``` Computes the sum of its operands. @@ -385,7 +385,7 @@ No other changes yet. ```grain -(-) : (Number, Number) -> Number +(-) : (x: Number, y: Number) -> Number ``` Computes the difference of its operands. @@ -411,7 +411,7 @@ No other changes yet. ```grain -(*) : (Number, Number) -> Number +(*) : (x: Number, y: Number) -> Number ``` Computes the product of its operands. @@ -437,7 +437,7 @@ No other changes yet. ```grain -(/) : (Number, Number) -> Number +(/) : (x: Number, y: Number) -> Number ``` Computes the quotient of its operands. @@ -463,7 +463,7 @@ No other changes yet. ```grain -(%) : (Number, Number) -> Number +(%) : (x: Number, y: Number) -> Number ``` Computes the remainder of the division of the first operand by the second. @@ -497,7 +497,7 @@ Returns: ```grain -(**) : (Number, Number) -> Number +(**) : (base: Number, power: Number) -> Number ``` Computes the exponentiation of the given base and power. @@ -523,7 +523,7 @@ No other changes yet. ```grain -incr : Number -> Number +incr : (x: Number) -> Number ``` Increments the value by one. @@ -548,7 +548,7 @@ No other changes yet. ```grain -decr : Number -> Number +decr : (x: Number) -> Number ``` Decrements the value by one. @@ -573,7 +573,7 @@ No other changes yet. ```grain -(++) : (String, String) -> String +(++) : (s1: String, s2: String) -> String ``` Concatenate two strings. @@ -605,7 +605,7 @@ No other changes yet. ```grain -lnot : Number -> Number +lnot : (x: Number) -> Number ``` Computes the bitwise NOT of the operand. @@ -638,7 +638,7 @@ Returns: ```grain -(&) : (Number, Number) -> Number +(&) : (x: Number, y: Number) -> Number ``` Computes the bitwise AND (`&`) on the given operands. @@ -672,7 +672,7 @@ Returns: ```grain -(|) : (Number, Number) -> Number +(|) : (x: Number, y: Number) -> Number ``` Computes the bitwise OR (`|`) on the given operands. @@ -707,7 +707,7 @@ Returns: ```grain -(^) : (Number, Number) -> Number +(^) : (x: Number, y: Number) -> Number ``` Computes the bitwise XOR (`^`) on the given operands. @@ -741,7 +741,7 @@ Returns: ```grain -(<<) : (Number, Number) -> Number +(<<) : (x: Number, y: Number) -> Number ``` Shifts the bits of the value left by the given number of bits. @@ -775,7 +775,7 @@ Returns: ```grain -(>>>) : (Number, Number) -> Number +(>>>) : (x: Number, y: Number) -> Number ``` Shifts the bits of the value right by the given number of bits, preserving the sign bit. @@ -809,7 +809,7 @@ Returns: ```grain -(>>) : (Number, Number) -> Number +(>>) : (x: Number, y: Number) -> Number ``` Shifts the bits of the value right by the given number of bits. @@ -835,7 +835,7 @@ No other changes yet. ```grain -toString : a -> String +toString : (value: a) -> String ``` Converts the given operand to a string. @@ -861,7 +861,7 @@ No other changes yet. ```grain -print : a -> Void +print : (value: a) -> Void ``` Prints the given operand to the console. Works for any type. Internally, calls `toString` @@ -982,7 +982,7 @@ No other changes yet. ```grain -identity : a -> a +identity : (x: a) -> a ``` Provides the operand untouched. diff --git a/stdlib/priorityqueue.md b/stdlib/priorityqueue.md index 1094db8010..b9a3529187 100644 --- a/stdlib/priorityqueue.md +++ b/stdlib/priorityqueue.md @@ -37,7 +37,7 @@ No other changes yet. ```grain -makeSized : (Number, ((a, a) -> Number)) -> PriorityQueue +makeSized : (size: Number, comp: ((a, a) -> Number)) -> PriorityQueue ``` Creates a new priority queue with a given internal storage size and a @@ -70,7 +70,7 @@ No other changes yet. ```grain -make : ((a, a) -> Number) -> PriorityQueue +make : (comp: ((a, a) -> Number)) -> PriorityQueue ``` Creates a new priority queue with a comparator function, which is used to @@ -108,7 +108,7 @@ No other changes yet. ```grain -size : PriorityQueue -> Number +size : (pq: PriorityQueue) -> Number ``` Gets the number of elements in a priority queue. @@ -133,7 +133,7 @@ No other changes yet. ```grain -isEmpty : PriorityQueue -> Bool +isEmpty : (pq: PriorityQueue) -> Bool ``` Determines if the priority queue contains no elements. @@ -158,7 +158,7 @@ No other changes yet. ```grain -push : (a, PriorityQueue) -> Void +push : (val: a, pq: PriorityQueue) -> Void ``` Adds a new element to the priority queue. @@ -178,7 +178,7 @@ No other changes yet. ```grain -peek : PriorityQueue -> Option +peek : (pq: PriorityQueue) -> Option ``` Retrieves the highest priority element in the priority queue. It is not @@ -204,7 +204,7 @@ No other changes yet. ```grain -pop : PriorityQueue -> Option +pop : (pq: PriorityQueue) -> Option ``` Removes and retrieves the highest priority element in the priority queue. @@ -229,7 +229,7 @@ No other changes yet. ```grain -drain : PriorityQueue -> List +drain : (pq: PriorityQueue) -> List ``` Clears the priority queue and produces a list of all of the elements in the priority @@ -255,7 +255,7 @@ No other changes yet. ```grain -fromArray : (Array, ((a, a) -> Number)) -> PriorityQueue +fromArray : (array: Array, comp: ((a, a) -> Number)) -> PriorityQueue ``` Constructs a new priority queue initialized with the elements in the array @@ -285,7 +285,7 @@ No other changes yet. ```grain -fromList : (List, ((a, a) -> Number)) -> PriorityQueue +fromList : (list: List, comp: ((a, a) -> Number)) -> PriorityQueue ``` Constructs a new priority queue initialized with the elements in the list diff --git a/stdlib/queue.md b/stdlib/queue.md index db6da2457a..28350e4cd7 100644 --- a/stdlib/queue.md +++ b/stdlib/queue.md @@ -41,7 +41,7 @@ No other changes yet. ```grain -makeSized : Number -> Queue +makeSized : (size: Number) -> Queue ``` Creates a new queue with an initial storage of the given size. As values are @@ -88,7 +88,7 @@ No other changes yet. ```grain -isEmpty : Queue -> Bool +isEmpty : (queue: Queue) -> Bool ``` Checks if the given queue contains no items. @@ -113,7 +113,7 @@ No other changes yet. ```grain -size : Queue -> Number +size : (queue: Queue) -> Number ``` Computes the size of the input queue. @@ -138,7 +138,7 @@ No other changes yet. ```grain -peek : Queue -> Option +peek : (queue: Queue) -> Option ``` Provides the value at the beginning of the queue, if it exists. @@ -163,7 +163,7 @@ No other changes yet. ```grain -push : (a, Queue) -> Void +push : (value: a, queue: Queue) -> Void ``` Adds a new item to the end of the queue. @@ -183,7 +183,7 @@ No other changes yet. ```grain -pop : Queue -> Option +pop : (queue: Queue) -> Option ``` Removes the item at the beginning of the queue. @@ -208,7 +208,7 @@ No other changes yet. ```grain -clear : Queue -> Void +clear : (queue: Queue) -> Void ``` Clears the queue by removing all of its elements @@ -227,7 +227,7 @@ No other changes yet. ```grain -copy : Queue -> Queue +copy : (queue: Queue) -> Queue ``` Produces a shallow copy of the input queue. @@ -299,7 +299,7 @@ An empty queue. ```grain -isEmpty : ImmutableQueue -> Bool +isEmpty : (queue: ImmutableQueue) -> Bool ``` Checks if the given queue contains any values. @@ -334,7 +334,7 @@ Returns: ```grain -peek : ImmutableQueue -> Option +peek : (queue: ImmutableQueue) -> Option ``` Returns the value at the beginning of the queue. It is not removed from the queue. @@ -369,7 +369,7 @@ Returns: ```grain -push : (a, ImmutableQueue) -> ImmutableQueue +push : (value: a, queue: ImmutableQueue) -> ImmutableQueue ``` Adds a value to the end of the queue. @@ -405,7 +405,7 @@ Returns: ```grain -pop : ImmutableQueue -> ImmutableQueue +pop : (queue: ImmutableQueue) -> ImmutableQueue ``` Dequeues the next value in the queue. @@ -437,7 +437,7 @@ Returns: ```grain -size : ImmutableQueue -> Number +size : (queue: ImmutableQueue) -> Number ``` Get the number of values in a queue. diff --git a/stdlib/random.md b/stdlib/random.md index 9b9a5aad8d..165a2e2645 100644 --- a/stdlib/random.md +++ b/stdlib/random.md @@ -35,7 +35,7 @@ No other changes yet. ```grain -make : Uint64 -> Random +make : (seed: Uint64) -> Random ``` Creates a new pseudo-random number generator with the given seed. @@ -86,7 +86,7 @@ Returns: ```grain -nextUint32 : Random -> Uint32 +nextUint32 : (random: Random) -> Uint32 ``` Generates a random 32-bit integer from the given pseudo-random number generator. @@ -118,7 +118,7 @@ Returns: ```grain -nextUint64 : Random -> Uint64 +nextUint64 : (random: Random) -> Uint64 ``` Generates a random 64-bit integer from the given pseudo-random number generator. @@ -150,7 +150,7 @@ Returns: ```grain -nextUint32InRange : (Random, Uint32, Uint32) -> Uint32 +nextUint32InRange : (random: Random, low: Uint32, high: Uint32) -> Uint32 ``` Generates a random 32-bit integer from the given pseudo-random number generator @@ -185,7 +185,7 @@ Returns: ```grain -nextUint64InRange : (Random, Uint64, Uint64) -> Uint64 +nextUint64InRange : (random: Random, low: Uint64, high: Uint64) -> Uint64 ``` Generates a random 64-bit integer from the given pseudo-random number generator diff --git a/stdlib/range.md b/stdlib/range.md index 7930508eab..4f70782aff 100644 --- a/stdlib/range.md +++ b/stdlib/range.md @@ -44,7 +44,7 @@ Functions and constants included in the Range module. ```grain -inRange : (Number, Range) -> Bool +inRange : (value: Number, range: Range) -> Bool ``` Checks if the given number is within the range. @@ -87,7 +87,7 @@ Range.inRange(10, { rangeStart: 0, rangeEnd: 2 }) == false ```grain -forEach : ((Number -> Void), Range) -> Void +forEach : (fn: (Number -> Void), range: Range) -> Void ``` Calls the given function with each number in the range. @@ -124,7 +124,7 @@ Range.forEach(val => print(val), { rangeStart: 0, rangeEnd: 2 }) ```grain -map : ((Number -> a), Range) -> List +map : (fn: (Number -> a), range: Range) -> List ``` Produces a list by calling the given function on each number included in the range. @@ -173,7 +173,7 @@ Functions and constants included in the Range.Inclusive module. ```grain -inRange : (Number, Range) -> Bool +inRange : (value: Number, range: Range) -> Bool ``` Checks if the given number is within the range. @@ -216,7 +216,7 @@ Range.Inclusive.inRange(10, { rangeStart: 0, rangeEnd: 2 }) == false ```grain -forEach : ((Number -> Void), Range) -> Void +forEach : (fn: (Number -> Void), range: Range) -> Void ``` Calls the given function with each number in the range. @@ -253,7 +253,7 @@ Range.Inclusive.forEach(val => print(val), { rangeStart: 0, rangeEnd: 2 }) ```grain -map : ((Number -> a), Range) -> List +map : (fn: (Number -> a), range: Range) -> List ``` Produces a list by calling the given function on each number included in the range. diff --git a/stdlib/rational.md b/stdlib/rational.md index 50125b9681..9f7275ecab 100644 --- a/stdlib/rational.md +++ b/stdlib/rational.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Rational +fromNumber : (x: Number) -> Rational ``` Converts a Number to a Rational. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Rational -> Number +toNumber : (x: Rational) -> Number ``` Converts a Rational to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -numerator : Rational -> Number +numerator : (x: Rational) -> Number ``` Finds the numerator of the rational number. @@ -100,7 +100,7 @@ No other changes yet. ```grain -denominator : Rational -> Number +denominator : (x: Rational) -> Number ``` Finds the denominator of the rational number. @@ -125,7 +125,7 @@ No other changes yet. ```grain -(+) : (Rational, Rational) -> Rational +(+) : (x: Rational, y: Rational) -> Rational ``` Computes the sum of its operands. @@ -151,7 +151,7 @@ No other changes yet. ```grain -(-) : (Rational, Rational) -> Rational +(-) : (x: Rational, y: Rational) -> Rational ``` Computes the difference of its operands. @@ -177,7 +177,7 @@ No other changes yet. ```grain -(*) : (Rational, Rational) -> Rational +(*) : (x: Rational, y: Rational) -> Rational ``` Computes the product of its operands. @@ -203,7 +203,7 @@ No other changes yet. ```grain -(/) : (Rational, Rational) -> Rational +(/) : (x: Rational, y: Rational) -> Rational ``` Computes the quotient of its operands. @@ -229,7 +229,7 @@ No other changes yet. ```grain -(==) : (Rational, Rational) -> Bool +(==) : (x: Rational, y: Rational) -> Bool ``` Checks if the first value is equal to the second value. @@ -255,7 +255,7 @@ No other changes yet. ```grain -(!=) : (Rational, Rational) -> Bool +(!=) : (x: Rational, y: Rational) -> Bool ``` Checks if the first value is not equal to the second value. @@ -281,7 +281,7 @@ No other changes yet. ```grain -(<) : (Rational, Rational) -> Bool +(<) : (x: Rational, y: Rational) -> Bool ``` Checks if the first value is less than the second value. @@ -307,7 +307,7 @@ No other changes yet. ```grain -(>) : (Rational, Rational) -> Bool +(>) : (x: Rational, y: Rational) -> Bool ``` Checks if the first value is greater than the second value. @@ -333,7 +333,7 @@ No other changes yet. ```grain -(<=) : (Rational, Rational) -> Bool +(<=) : (x: Rational, y: Rational) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -359,7 +359,7 @@ No other changes yet. ```grain -(>=) : (Rational, Rational) -> Bool +(>=) : (x: Rational, y: Rational) -> Bool ``` Checks if the first value is greater than or equal to the second value. diff --git a/stdlib/regex.md b/stdlib/regex.md index f103f468ee..36a2a47978 100644 --- a/stdlib/regex.md +++ b/stdlib/regex.md @@ -87,7 +87,7 @@ No other changes yet. ```grain -make : String -> Result +make : (regexString: String) -> Result ``` Compiles the given pattern string into a regular expression object. @@ -200,7 +200,7 @@ No other changes yet. ```grain -isMatch : (RegularExpression, String) -> Bool +isMatch : (rx: RegularExpression, string: String) -> Bool ``` Determines if the given regular expression has a match in the given string. @@ -232,7 +232,8 @@ No other changes yet. ```grain -isMatchRange : (RegularExpression, String, Number, Number) -> Bool +isMatchRange : + (rx: RegularExpression, string: String, start: Number, end: Number) -> Bool ``` Determines if the given regular expression has a match in the given string between the given start/end offsets. @@ -270,7 +271,7 @@ No other changes yet. ```grain -find : (RegularExpression, String) -> Option +find : (rx: RegularExpression, string: String) -> Option ``` Returns the first match for the given regular expression contained within the given string. @@ -303,7 +304,8 @@ No other changes yet. ```grain findRange : - (RegularExpression, String, Number, Number) -> Option + (rx: RegularExpression, string: String, start: Number, end: Number) -> + Option ``` Returns the first match for the given regular expression contained within the given string @@ -333,7 +335,7 @@ Regex.findRange(Result.unwrap(Regex.make("ca+[at]")), "caaat", 0, 5) ### Regex.**findAll** ```grain -findAll : (RegularExpression, String) -> List +findAll : (rx: RegularExpression, string: String) -> List ``` Returns all matches for the given regular expression contained within the given string. @@ -360,7 +362,8 @@ No other changes yet. ```grain findAllRange : - (RegularExpression, String, Number, Number) -> List + (rx: RegularExpression, string: String, start: Number, end: Number) -> + List ``` Returns all matches for the given regular expression contained within the given string @@ -395,7 +398,8 @@ No other changes yet. ```grain -replace : (RegularExpression, String, String) -> String +replace : + (rx: RegularExpression, toSearch: String, replacement: String) -> String ``` Replaces the first match for the given regular expression contained within the given string with the specified replacement. @@ -436,7 +440,8 @@ No other changes yet. ```grain -replaceAll : (RegularExpression, String, String) -> String +replaceAll : + (rx: RegularExpression, toSearch: String, replacement: String) -> String ``` Replaces all matches for the given regular expression contained within the given string with the specified replacement. @@ -470,7 +475,7 @@ No other changes yet. ```grain -split : (RegularExpression, String) -> List +split : (rx: RegularExpression, str: String) -> List ``` Splits the given string at the first match for the given regular expression. @@ -505,7 +510,7 @@ No other changes yet. ```grain -splitAll : (RegularExpression, String) -> List +splitAll : (rx: RegularExpression, str: String) -> List ``` Splits the given string at every match for the given regular expression. diff --git a/stdlib/result.md b/stdlib/result.md index 7996da2887..be12af3a63 100644 --- a/stdlib/result.md +++ b/stdlib/result.md @@ -36,7 +36,7 @@ No other changes yet. ```grain -isOk : Result -> Bool +isOk : (result: Result) -> Bool ``` Checks if the Result is the `Ok` variant. @@ -61,7 +61,7 @@ No other changes yet. ```grain -isErr : Result -> Bool +isErr : (result: Result) -> Bool ``` Checks if the Result is the `Err` variant. @@ -86,7 +86,7 @@ No other changes yet. ```grain -toOption : Result -> Option +toOption : (result: Result) -> Option ``` Converts the Result to an Option. An error value is discarded and replaced with `None`. @@ -111,7 +111,7 @@ No other changes yet. ```grain -flatMap : ((a -> Result), Result) -> Result +flatMap : (fn: (a -> Result), result: Result) -> Result ``` If the Result is `Ok(value)`, applies the given function to the `value` to produce a new Result. @@ -137,7 +137,7 @@ No other changes yet. ```grain -flatMapErr : ((a -> Result), Result) -> Result +flatMapErr : (fn: (a -> Result), result: Result) -> Result ``` If the Result is an `Err(value)`, applies the given function to the `value` to produce a new Result. @@ -163,7 +163,7 @@ No other changes yet. ```grain -map : ((a -> b), Result) -> Result +map : (fn: (a -> b), result: Result) -> Result ``` If the Result is `Ok(value)`, applies the given function to the `value` and wraps the new value in an `Ok` variant. @@ -189,7 +189,7 @@ No other changes yet. ```grain -mapErr : ((a -> b), Result) -> Result +mapErr : (fn: (a -> b), result: Result) -> Result ``` If the Result is `Err(value)`, applies the given function to the `value` and wraps the new value in an `Err` variant. @@ -215,7 +215,7 @@ No other changes yet. ```grain -mapWithDefault : ((a -> b), b, Result) -> b +mapWithDefault : (fn: (a -> b), def: b, result: Result) -> b ``` If the Result is `Ok(value)`, applies the given function to the `value` to produce a new value, otherwise uses the default value. @@ -243,7 +243,8 @@ No other changes yet. ```grain -mapWithDefaultFn : ((a -> b), (c -> b), Result) -> b +mapWithDefaultFn : + (fnOk: (a -> b), fnErr: (c -> b), result: Result) -> b ``` If the Result is `Ok(value)`, applies the `fnOk` function to the `value` to produce a new value. @@ -272,7 +273,7 @@ No other changes yet. ```grain -or : (Result, Result) -> Result +or : (result1: Result, result2: Result) -> Result ``` Behaves like a logical OR (`||`) where the first Result is only returned if it is the `Ok` variant and falling back to the second Result in all other cases. @@ -298,7 +299,7 @@ No other changes yet. ```grain -and : (Result, Result) -> Result +and : (result1: Result, result2: Result) -> Result ``` Behaves like a logical AND (`&&`) where the first Result is only returned if it is the `Err` variant and falling back to the second Result in all other cases. @@ -324,7 +325,7 @@ No other changes yet. ```grain -peek : ((a -> b), (c -> d), Result) -> Void +peek : (fnOk: (a -> b), fnErr: (c -> d), result: Result) -> Void ``` If the Result is `Ok(value)`, applies the `fnOk` function to the `value` without producing a new value. @@ -347,7 +348,7 @@ No other changes yet. ```grain -peekOk : ((a -> b), Result) -> Void +peekOk : (fn: (a -> b), result: Result) -> Void ``` If the Result is `Ok(value)`, applies the given function to the `value` without producing a new value. @@ -367,7 +368,7 @@ No other changes yet. ```grain -peekErr : ((a -> b), Result) -> Void +peekErr : (fn: (a -> b), result: Result) -> Void ``` If the Result is `Err(value)`, applies the given function to the `value` without producing a new value. @@ -387,7 +388,7 @@ No other changes yet. ```grain -expect : (String, Result) -> a +expect : (msg: String, result: Result) -> a ``` Extracts the value inside an `Ok` result, otherwise throw an @@ -426,7 +427,7 @@ No other changes yet. ```grain -unwrap : Result -> a +unwrap : (result: Result) -> a ``` Extracts the value inside an `Ok` result, otherwise throw an diff --git a/stdlib/runtime/atof/common.md b/stdlib/runtime/atof/common.md index ca085e367c..05fa1ed3fe 100644 --- a/stdlib/runtime/atof/common.md +++ b/stdlib/runtime/atof/common.md @@ -220,36 +220,36 @@ fpNan : () -> BiasedFp ### Common.**getPowers10** ```grain -getPowers10 : WasmI32 -> WasmI32 +getPowers10 : (i: WasmI32) -> WasmI32 ``` ### Common.**getPowers10FastPath** ```grain -getPowers10FastPath : WasmI32 -> WasmF64 +getPowers10FastPath : (i: WasmI32) -> WasmF64 ``` ### Common.**is8Digits** ```grain -is8Digits : WasmI64 -> Bool +is8Digits : (value: WasmI64) -> Bool ``` ### Common.**power** ```grain -power : WasmI32 -> WasmI32 +power : (q: WasmI32) -> WasmI32 ``` ### Common.**fullMultiplication** ```grain -fullMultiplication : (WasmI64, WasmI64) -> (Int64, Int64) +fullMultiplication : (a: WasmI64, b: WasmI64) -> (Int64, Int64) ``` ### Common.**biasedFpToNumber** ```grain -biasedFpToNumber : (BiasedFp, Bool) -> Number +biasedFpToNumber : (fp: BiasedFp, negative: Bool) -> Number ``` diff --git a/stdlib/runtime/atof/decimal.md b/stdlib/runtime/atof/decimal.md index b866a330ad..e1427b4189 100644 --- a/stdlib/runtime/atof/decimal.md +++ b/stdlib/runtime/atof/decimal.md @@ -30,13 +30,13 @@ _DECIMAL_POINT_RANGE : WasmI32 ### Decimal.**tryAddDigit** ```grain -tryAddDigit : (Decimal, WasmI32) -> Void +tryAddDigit : (d: Decimal, digit: WasmI32) -> Void ``` ### Decimal.**round** ```grain -round : Decimal -> WasmI64 +round : (d: Decimal) -> WasmI64 ``` ### Decimal.**get_TABLE** @@ -54,18 +54,18 @@ get_TABLE_POW5 : () -> WasmI32 ### Decimal.**leftShift** ```grain -leftShift : (Decimal, WasmI32) -> Void +leftShift : (d: Decimal, shift: WasmI32) -> Void ``` ### Decimal.**rightShift** ```grain -rightShift : (Decimal, WasmI32) -> Void +rightShift : (d: Decimal, shift: WasmI32) -> Void ``` ### Decimal.**parseDecimal** ```grain -parseDecimal : String -> Decimal +parseDecimal : (s: String) -> Decimal ``` diff --git a/stdlib/runtime/atof/lemire.md b/stdlib/runtime/atof/lemire.md index 008c861358..3043f5b118 100644 --- a/stdlib/runtime/atof/lemire.md +++ b/stdlib/runtime/atof/lemire.md @@ -9,6 +9,6 @@ Functions and constants included in the Lemire module. ### Lemire.**computeFloat** ```grain -computeFloat : (WasmI64, WasmI64) -> Common.BiasedFp +computeFloat : (exponent: WasmI64, mantissa: WasmI64) -> Common.BiasedFp ``` diff --git a/stdlib/runtime/atof/parse.md b/stdlib/runtime/atof/parse.md index 661c076832..9670e201c6 100644 --- a/stdlib/runtime/atof/parse.md +++ b/stdlib/runtime/atof/parse.md @@ -9,12 +9,14 @@ Functions and constants included in the Parse module. ### Parse.**isFastPath** ```grain -isFastPath : (WasmI32, WasmI64, Bool, Bool) -> Bool +isFastPath : + (exponent: WasmI32, mantissa: WasmI64, negative: Bool, manyDigits: Bool) -> + Bool ``` ### Parse.**parseFloat** ```grain -parseFloat : String -> Result +parseFloat : (string: String) -> Result ``` diff --git a/stdlib/runtime/atof/slow.md b/stdlib/runtime/atof/slow.md index f4d0054e7f..156471f16a 100644 --- a/stdlib/runtime/atof/slow.md +++ b/stdlib/runtime/atof/slow.md @@ -9,6 +9,6 @@ Functions and constants included in the Slow module. ### Slow.**parseLongMantissa** ```grain -parseLongMantissa : String -> Common.BiasedFp +parseLongMantissa : (s: String) -> Common.BiasedFp ``` diff --git a/stdlib/runtime/atoi/parse.md b/stdlib/runtime/atoi/parse.md index ab4f593faa..9b3ca6c507 100644 --- a/stdlib/runtime/atoi/parse.md +++ b/stdlib/runtime/atoi/parse.md @@ -9,6 +9,6 @@ Functions and constants included in the Parse module. ### Parse.**parseInt** ```grain -parseInt : (String, Number) -> Result +parseInt : (string: String, radix: Number) -> Result ``` diff --git a/stdlib/runtime/bigint.md b/stdlib/runtime/bigint.md index 71502f8f89..47d2ad61fe 100644 --- a/stdlib/runtime/bigint.md +++ b/stdlib/runtime/bigint.md @@ -9,61 +9,61 @@ Functions and constants included in the Bigint module. ### Bigint.**debugDumpNumber** ```grain -debugDumpNumber : WasmI32 -> Void +debugDumpNumber : (num: WasmI32) -> Void ``` ### Bigint.**getSize** ```grain -getSize : WasmI32 -> WasmI32 +getSize : (ptr: WasmI32) -> WasmI32 ``` ### Bigint.**getFlags** ```grain -getFlags : WasmI32 -> WasmI32 +getFlags : (ptr: WasmI32) -> WasmI32 ``` ### Bigint.**getLimb** ```grain -getLimb : (WasmI32, WasmI32) -> WasmI64 +getLimb : (ptr: WasmI32, i: WasmI32) -> WasmI64 ``` ### Bigint.**makeWrappedInt32** ```grain -makeWrappedInt32 : WasmI32 -> WasmI32 +makeWrappedInt32 : (value: WasmI32) -> WasmI32 ``` ### Bigint.**makeWrappedUint32** ```grain -makeWrappedUint32 : WasmI32 -> WasmI32 +makeWrappedUint32 : (value: WasmI32) -> WasmI32 ``` ### Bigint.**makeWrappedInt64** ```grain -makeWrappedInt64 : WasmI64 -> WasmI32 +makeWrappedInt64 : (value: WasmI64) -> WasmI32 ``` ### Bigint.**makeWrappedUint64** ```grain -makeWrappedUint64 : WasmI64 -> WasmI32 +makeWrappedUint64 : (value: WasmI64) -> WasmI32 ``` ### Bigint.**isNegative** ```grain -isNegative : WasmI32 -> Bool +isNegative : (num: WasmI32) -> Bool ``` ### Bigint.**eqz** ```grain -eqz : WasmI32 -> Bool +eqz : (num: WasmI32) -> Bool ``` Returns true if the given bigint is equal to zero @@ -71,270 +71,270 @@ Returns true if the given bigint is equal to zero ### Bigint.**negate** ```grain -negate : WasmI32 -> WasmI32 +negate : (num: WasmI32) -> WasmI32 ``` ### Bigint.**abs** ```grain -abs : WasmI32 -> WasmI32 +abs : (num: WasmI32) -> WasmI32 ``` ### Bigint.**canConvertToInt32** ```grain -canConvertToInt32 : WasmI32 -> Bool +canConvertToInt32 : (num: WasmI32) -> Bool ``` ### Bigint.**toInt32** ```grain -toInt32 : WasmI32 -> WasmI32 +toInt32 : (num: WasmI32) -> WasmI32 ``` ### Bigint.**canConvertToInt64** ```grain -canConvertToInt64 : WasmI32 -> Bool +canConvertToInt64 : (num: WasmI32) -> Bool ``` ### Bigint.**toInt64** ```grain -toInt64 : WasmI32 -> WasmI64 +toInt64 : (num: WasmI32) -> WasmI64 ``` ### Bigint.**toUnsignedInt64** ```grain -toUnsignedInt64 : WasmI32 -> WasmI64 +toUnsignedInt64 : (num: WasmI32) -> WasmI64 ``` ### Bigint.**toFloat64** ```grain -toFloat64 : WasmI32 -> WasmF64 +toFloat64 : (num: WasmI32) -> WasmF64 ``` ### Bigint.**toFloat32** ```grain -toFloat32 : WasmI32 -> WasmF32 +toFloat32 : (num: WasmI32) -> WasmF32 ``` ### Bigint.**cmpI64** ```grain -cmpI64 : (WasmI32, WasmI64) -> WasmI32 +cmpI64 : (num1: WasmI32, num2: WasmI64) -> WasmI32 ``` ### Bigint.**cmpU64** ```grain -cmpU64 : (WasmI32, WasmI64) -> WasmI32 +cmpU64 : (num1: WasmI32, num2: WasmI64) -> WasmI32 ``` ### Bigint.**cmpF64** ```grain -cmpF64 : (WasmI32, WasmF64) -> WasmI32 +cmpF64 : (num1: WasmI32, num2: WasmF64) -> WasmI32 ``` ### Bigint.**cmpF32** ```grain -cmpF32 : (WasmI32, WasmF32) -> WasmI32 +cmpF32 : (num1: WasmI32, num2: WasmF32) -> WasmI32 ``` ### Bigint.**cmp** ```grain -cmp : (WasmI32, WasmI32) -> WasmI32 +cmp : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**eq** ```grain -eq : (WasmI32, WasmI32) -> Bool +eq : (num1: WasmI32, num2: WasmI32) -> Bool ``` ### Bigint.**ne** ```grain -ne : (WasmI32, WasmI32) -> Bool +ne : (num1: WasmI32, num2: WasmI32) -> Bool ``` ### Bigint.**lt** ```grain -lt : (WasmI32, WasmI32) -> Bool +lt : (num1: WasmI32, num2: WasmI32) -> Bool ``` ### Bigint.**lte** ```grain -lte : (WasmI32, WasmI32) -> Bool +lte : (num1: WasmI32, num2: WasmI32) -> Bool ``` ### Bigint.**gt** ```grain -gt : (WasmI32, WasmI32) -> Bool +gt : (num1: WasmI32, num2: WasmI32) -> Bool ``` ### Bigint.**gte** ```grain -gte : (WasmI32, WasmI32) -> Bool +gte : (num1: WasmI32, num2: WasmI32) -> Bool ``` ### Bigint.**bigIntToString** ```grain -bigIntToString : (WasmI32, WasmI32) -> String +bigIntToString : (num: WasmI32, base: WasmI32) -> String ``` ### Bigint.**bigIntToString10** ```grain -bigIntToString10 : WasmI32 -> String +bigIntToString10 : (num: WasmI32) -> String ``` ### Bigint.**add** ```grain -add : (WasmI32, WasmI32) -> WasmI32 +add : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**addInt** ```grain -addInt : (WasmI32, WasmI64) -> WasmI32 +addInt : (num1: WasmI32, int: WasmI64) -> WasmI32 ``` ### Bigint.**sub** ```grain -sub : (WasmI32, WasmI32) -> WasmI32 +sub : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**subInt** ```grain -subInt : (WasmI32, WasmI64) -> WasmI32 +subInt : (num1: WasmI32, int: WasmI64) -> WasmI32 ``` ### Bigint.**incr** ```grain -incr : WasmI32 -> WasmI32 +incr : (num: WasmI32) -> WasmI32 ``` ### Bigint.**decr** ```grain -decr : WasmI32 -> WasmI32 +decr : (num: WasmI32) -> WasmI32 ``` ### Bigint.**mul** ```grain -mul : (WasmI32, WasmI32) -> WasmI32 +mul : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**shl** ```grain -shl : (WasmI32, WasmI32) -> WasmI32 +shl : (num: WasmI32, places: WasmI32) -> WasmI32 ``` ### Bigint.**shrS** ```grain -shrS : (WasmI32, WasmI32) -> WasmI32 +shrS : (num: WasmI32, places: WasmI32) -> WasmI32 ``` ### Bigint.**bitwiseNot** ```grain -bitwiseNot : WasmI32 -> WasmI32 +bitwiseNot : (num: WasmI32) -> WasmI32 ``` ### Bigint.**bitwiseAnd** ```grain -bitwiseAnd : (WasmI32, WasmI32) -> WasmI32 +bitwiseAnd : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**bitwiseOr** ```grain -bitwiseOr : (WasmI32, WasmI32) -> WasmI32 +bitwiseOr : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**bitwiseXor** ```grain -bitwiseXor : (WasmI32, WasmI32) -> WasmI32 +bitwiseXor : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**countLeadingZeros** ```grain -countLeadingZeros : WasmI32 -> WasmI32 +countLeadingZeros : (num: WasmI32) -> WasmI32 ``` ### Bigint.**countTrailingZeros** ```grain -countTrailingZeros : WasmI32 -> WasmI64 +countTrailingZeros : (num: WasmI32) -> WasmI64 ``` ### Bigint.**popcnt** ```grain -popcnt : (WasmI32, WasmI32) -> WasmI64 +popcnt : (num: WasmI32, flagDest: WasmI32) -> WasmI64 ``` ### Bigint.**gcd** ```grain -gcd : (WasmI32, WasmI32) -> WasmI32 +gcd : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**quotRem** ```grain -quotRem : (WasmI32, WasmI32, WasmI32) -> Void +quotRem : (num1: WasmI32, num2: WasmI32, dest: WasmI32) -> Void ``` ### Bigint.**divMod** ```grain -divMod : (WasmI32, WasmI32, WasmI32) -> Void +divMod : (num1: WasmI32, num2: WasmI32, dest: WasmI32) -> Void ``` ### Bigint.**quot** ```grain -quot : (WasmI32, WasmI32) -> WasmI32 +quot : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**div** ```grain -div : (WasmI32, WasmI32) -> WasmI32 +div : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**rem** ```grain -rem : (WasmI32, WasmI32) -> WasmI32 +rem : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` ### Bigint.**mod** ```grain -mod : (WasmI32, WasmI32) -> WasmI32 +mod : (num1: WasmI32, num2: WasmI32) -> WasmI32 ``` diff --git a/stdlib/runtime/compare.md b/stdlib/runtime/compare.md index 3739565c37..6c6a9e1937 100644 --- a/stdlib/runtime/compare.md +++ b/stdlib/runtime/compare.md @@ -14,7 +14,7 @@ No other changes yet. ```grain -compare : (a, a) -> Number +compare : (x: a, y: a) -> Number ``` Compares the first argument to the second argument and produces an integer result. diff --git a/stdlib/runtime/debugPrint.md b/stdlib/runtime/debugPrint.md index b4fa2fc815..007286c13a 100644 --- a/stdlib/runtime/debugPrint.md +++ b/stdlib/runtime/debugPrint.md @@ -9,30 +9,30 @@ Functions and constants included in the DebugPrint module. ### DebugPrint.**print** ```grain -print : String -> Void +print : (s: String) -> Void ``` ### DebugPrint.**printI32** ```grain -printI32 : WasmI32 -> Void +printI32 : (val: WasmI32) -> Void ``` ### DebugPrint.**printI64** ```grain -printI64 : WasmI64 -> Void +printI64 : (val: WasmI64) -> Void ``` ### DebugPrint.**printF32** ```grain -printF32 : WasmF32 -> Void +printF32 : (val: WasmF32) -> Void ``` ### DebugPrint.**printF64** ```grain -printF64 : WasmF64 -> Void +printF64 : (val: WasmF64) -> Void ``` diff --git a/stdlib/runtime/equal.md b/stdlib/runtime/equal.md index d2b66bffdf..1d2b5747de 100644 --- a/stdlib/runtime/equal.md +++ b/stdlib/runtime/equal.md @@ -14,7 +14,7 @@ No other changes yet. ```grain -equal : (a, a) -> Bool +equal : (x: a, y: a) -> Bool ``` Check that two values are equal. This checks for structural equality, diff --git a/stdlib/runtime/exception.md b/stdlib/runtime/exception.md index 3d269d9bce..a4501cce89 100644 --- a/stdlib/runtime/exception.md +++ b/stdlib/runtime/exception.md @@ -15,24 +15,24 @@ printers : WasmI32 ### Exception.**dangerouslyRegisterBasePrinter** ```grain -dangerouslyRegisterBasePrinter : a -> Void +dangerouslyRegisterBasePrinter : (f: a) -> Void ``` ### Exception.**dangerouslyRegisterPrinter** ```grain -dangerouslyRegisterPrinter : a -> Void +dangerouslyRegisterPrinter : (f: a) -> Void ``` ### Exception.**panic** ```grain -panic : String -> a +panic : (msg: String) -> a ``` ### Exception.**panicWithException** ```grain -panicWithException : Exception -> a +panicWithException : (e: Exception) -> a ``` diff --git a/stdlib/runtime/gc.md b/stdlib/runtime/gc.md index a93c4b7869..10a1b53bc2 100644 --- a/stdlib/runtime/gc.md +++ b/stdlib/runtime/gc.md @@ -9,24 +9,24 @@ Functions and constants included in the GC module. ### GC.**malloc** ```grain -malloc : WasmI32 -> WasmI32 +malloc : (size: WasmI32) -> WasmI32 ``` ### GC.**free** ```grain -free : WasmI32 -> Void +free : (userPtr: WasmI32) -> Void ``` ### GC.**incRef** ```grain -incRef : WasmI32 -> WasmI32 +incRef : (userPtr: WasmI32) -> WasmI32 ``` ### GC.**decRef** ```grain -decRef : WasmI32 -> WasmI32 +decRef : (userPtr: WasmI32) -> WasmI32 ``` diff --git a/stdlib/runtime/malloc.md b/stdlib/runtime/malloc.md index 3e900eea20..74766332ad 100644 --- a/stdlib/runtime/malloc.md +++ b/stdlib/runtime/malloc.md @@ -15,7 +15,7 @@ _RESERVED_RUNTIME_SPACE : WasmI32 ### Malloc.**free** ```grain -free : WasmI32 -> Void +free : (ap: WasmI32) -> Void ``` Frees the given allocated pointer. @@ -29,7 +29,7 @@ Parameters: ### Malloc.**malloc** ```grain -malloc : WasmI32 -> WasmI32 +malloc : (nb: WasmI32) -> WasmI32 ``` Allocates the requested number of bytes, returning a pointer. diff --git a/stdlib/runtime/numberUtils.md b/stdlib/runtime/numberUtils.md index 0d0efa579b..7005efc98e 100644 --- a/stdlib/runtime/numberUtils.md +++ b/stdlib/runtime/numberUtils.md @@ -27,42 +27,42 @@ get_HEX_DIGITS : () -> WasmI32 ### NumberUtils.**decimalCount32** ```grain -decimalCount32 : WasmI32 -> WasmI32 +decimalCount32 : (value: WasmI32) -> WasmI32 ``` ### NumberUtils.**utoa32Buffered** ```grain -utoa32Buffered : (WasmI32, WasmI32, WasmI32) -> Void +utoa32Buffered : (buf: WasmI32, value: WasmI32, radix: WasmI32) -> Void ``` ### NumberUtils.**utoa32** ```grain -utoa32 : (WasmI32, WasmI32) -> String +utoa32 : (value: WasmI32, radix: WasmI32) -> String ``` ### NumberUtils.**itoa32** ```grain -itoa32 : (WasmI32, WasmI32) -> String +itoa32 : (value: WasmI32, radix: WasmI32) -> String ``` ### NumberUtils.**utoa64** ```grain -utoa64 : (WasmI64, WasmI32) -> String +utoa64 : (value: WasmI64, radix: WasmI32) -> String ``` ### NumberUtils.**itoa64** ```grain -itoa64 : (WasmI64, WasmI32) -> String +itoa64 : (value: WasmI64, radix: WasmI32) -> String ``` ### NumberUtils.**dtoa** ```grain -dtoa : WasmF64 -> String +dtoa : (value: WasmF64) -> String ``` diff --git a/stdlib/runtime/numbers.md b/stdlib/runtime/numbers.md index 2f75d595ba..595402c560 100644 --- a/stdlib/runtime/numbers.md +++ b/stdlib/runtime/numbers.md @@ -9,151 +9,153 @@ Functions and constants included in the Numbers module. ### Numbers.**tagSimple** ```grain -tagSimple : WasmI32 -> WasmI32 +tagSimple : (x: WasmI32) -> WasmI32 ``` ### Numbers.**isBoxedNumber** ```grain -isBoxedNumber : WasmI32 -> Bool +isBoxedNumber : (x: WasmI32) -> Bool ``` ### Numbers.**isFloat** ```grain -isFloat : WasmI32 -> Bool +isFloat : (x: WasmI32) -> Bool ``` ### Numbers.**isInteger** ```grain -isInteger : WasmI32 -> Bool +isInteger : (x: WasmI32) -> Bool ``` ### Numbers.**isRational** ```grain -isRational : WasmI32 -> Bool +isRational : (x: WasmI32) -> Bool ``` ### Numbers.**isNaN** ```grain -isNaN : WasmI32 -> Bool +isNaN : (x: WasmI32) -> Bool ``` ### Numbers.**isNumber** ```grain -isNumber : WasmI32 -> Bool +isNumber : (x: WasmI32) -> Bool ``` ### Numbers.**reducedInteger** ```grain -reducedInteger : WasmI64 -> WasmI32 +reducedInteger : (x: WasmI64) -> WasmI32 ``` ### Numbers.**reducedUnsignedInteger** ```grain -reducedUnsignedInteger : WasmI64 -> WasmI32 +reducedUnsignedInteger : (x: WasmI64) -> WasmI32 ``` ### Numbers.**boxedNumberTag** ```grain -boxedNumberTag : WasmI32 -> WasmI32 +boxedNumberTag : (xptr: WasmI32) -> WasmI32 ``` ### Numbers.**boxedInt64Number** ```grain -boxedInt64Number : WasmI32 -> WasmI64 +boxedInt64Number : (xptr: WasmI32) -> WasmI64 ``` ### Numbers.**boxedFloat64Number** ```grain -boxedFloat64Number : WasmI32 -> WasmF64 +boxedFloat64Number : (xptr: WasmI32) -> WasmF64 ``` ### Numbers.**boxedRationalNumerator** ```grain -boxedRationalNumerator : WasmI32 -> WasmI32 +boxedRationalNumerator : (xptr: WasmI32) -> WasmI32 ``` ### Numbers.**boxedRationalDenominator** ```grain -boxedRationalDenominator : WasmI32 -> WasmI32 +boxedRationalDenominator : (xptr: WasmI32) -> WasmI32 ``` ### Numbers.**coerceNumberToWasmF32** ```grain -coerceNumberToWasmF32 : Number -> WasmF32 +coerceNumberToWasmF32 : (x: Number) -> WasmF32 ``` ### Numbers.**coerceNumberToWasmF64** ```grain -coerceNumberToWasmF64 : Number -> WasmF64 +coerceNumberToWasmF64 : (x: Number) -> WasmF64 ``` ### Numbers.**coerceNumberToWasmI64** ```grain -coerceNumberToWasmI64 : Number -> WasmI64 +coerceNumberToWasmI64 : (x: Number) -> WasmI64 ``` ### Numbers.**coerceNumberToWasmI32** ```grain -coerceNumberToWasmI32 : Number -> WasmI32 +coerceNumberToWasmI32 : (x: Number) -> WasmI32 ``` ### Numbers.**coerceNumberToUnsignedWasmI64** ```grain -coerceNumberToUnsignedWasmI64 : Number -> WasmI64 +coerceNumberToUnsignedWasmI64 : (x: Number) -> WasmI64 ``` ### Numbers.**coerceNumberToUnsignedWasmI32** ```grain -coerceNumberToUnsignedWasmI32 : Number -> WasmI32 +coerceNumberToUnsignedWasmI32 : (x: Number) -> WasmI32 ``` ### Numbers.**numberEqual** ```grain -numberEqual : (WasmI32, WasmI32) -> Bool +numberEqual : (x: WasmI32, y: WasmI32) -> Bool ``` ### Numbers.**addSubRational** ```grain -addSubRational : (WasmI32, WasmI32, Bool, Bool) -> WasmI32 +addSubRational : + (x: WasmI32, y: WasmI32, isSub: Bool, keepRational: Bool) -> WasmI32 ``` ### Numbers.**timesDivideRational** ```grain -timesDivideRational : (WasmI32, WasmI32, Bool, Bool) -> WasmI32 +timesDivideRational : + (x: WasmI32, y: WasmI32, isDivide: Bool, keepRational: Bool) -> WasmI32 ``` ### Numbers.**rationalsEqual** ```grain -rationalsEqual : (WasmI32, WasmI32) -> Bool +rationalsEqual : (x: WasmI32, y: WasmI32) -> Bool ``` ### Numbers.**cmpRationals** ```grain -cmpRationals : (WasmI32, WasmI32) -> WasmI32 +cmpRationals : (x: WasmI32, y: WasmI32) -> WasmI32 ``` ### Numbers.**rationalNumerator** @@ -164,7 +166,7 @@ No other changes yet. ```grain -rationalNumerator : Rational -> Number +rationalNumerator : (x: Rational) -> Number ``` Finds the numerator of the rational number. @@ -189,7 +191,7 @@ No other changes yet. ```grain -rationalDenominator : Rational -> Number +rationalDenominator : (x: Rational) -> Number ``` Finds the denominator of the rational number. @@ -209,7 +211,7 @@ Returns: ### Numbers.**cmp** ```grain -cmp : (WasmI32, WasmI32) -> WasmI32 +cmp : (x: WasmI32, y: WasmI32) -> WasmI32 ``` ### Numbers.**(<)** @@ -220,7 +222,7 @@ No other changes yet. ```grain -(<) : (Number, Number) -> Bool +(<) : (x: Number, y: Number) -> Bool ``` Checks if the first operand is less than the second operand. @@ -246,7 +248,7 @@ No other changes yet. ```grain -(>) : (Number, Number) -> Bool +(>) : (x: Number, y: Number) -> Bool ``` Checks if the first operand is greater than the second operand. @@ -272,7 +274,7 @@ No other changes yet. ```grain -(<=) : (Number, Number) -> Bool +(<=) : (x: Number, y: Number) -> Bool ``` Checks if the first operand is less than or equal to the second operand. @@ -298,7 +300,7 @@ No other changes yet. ```grain -(>=) : (Number, Number) -> Bool +(>=) : (x: Number, y: Number) -> Bool ``` Checks if the first operand is greater than or equal to the second operand. @@ -319,13 +321,13 @@ Returns: ### Numbers.**compare** ```grain -compare : (Number, Number) -> Number +compare : (x: Number, y: Number) -> Number ``` ### Numbers.**numberEq** ```grain -numberEq : (Number, Number) -> Bool +numberEq : (x: Number, y: Number) -> Bool ``` ### Numbers.**lnot** @@ -336,7 +338,7 @@ No other changes yet. ```grain -lnot : Number -> Number +lnot : (x: Number) -> Number ``` Computes the bitwise NOT of the operand. @@ -369,7 +371,7 @@ Returns: ```grain -(<<) : (Number, Number) -> Number +(<<) : (x: Number, y: Number) -> Number ``` Shifts the bits of the value left by the given number of bits. @@ -403,7 +405,7 @@ Returns: ```grain -(>>>) : (Number, Number) -> Number +(>>>) : (x: Number, y: Number) -> Number ``` Shifts the bits of the value right by the given number of bits, preserving the sign bit. @@ -437,7 +439,7 @@ Returns: ```grain -(&) : (Number, Number) -> Number +(&) : (x: Number, y: Number) -> Number ``` Computes the bitwise AND (`&`) on the given operands. @@ -471,7 +473,7 @@ Returns: ```grain -(|) : (Number, Number) -> Number +(|) : (x: Number, y: Number) -> Number ``` Computes the bitwise OR (`|`) on the given operands. @@ -506,7 +508,7 @@ Returns: ```grain -(^) : (Number, Number) -> Number +(^) : (x: Number, y: Number) -> Number ``` Computes the bitwise XOR (`^`) on the given operands. @@ -540,7 +542,7 @@ Returns: ```grain -(>>) : (Number, Number) -> Number +(>>) : (x: Number, y: Number) -> Number ``` Shifts the bits of the value right by the given number of bits. @@ -566,7 +568,7 @@ No other changes yet. ```grain -coerceNumberToInt8 : Number -> Int8 +coerceNumberToInt8 : (number: Number) -> Int8 ``` Converts a Number to an Int8. @@ -591,7 +593,7 @@ No other changes yet. ```grain -coerceNumberToInt16 : Number -> Int16 +coerceNumberToInt16 : (number: Number) -> Int16 ``` Converts a Number to an Int16. @@ -616,7 +618,7 @@ No other changes yet. ```grain -coerceNumberToUint8 : Number -> Uint8 +coerceNumberToUint8 : (number: Number) -> Uint8 ``` Converts a Number to a Uint8. @@ -641,7 +643,7 @@ No other changes yet. ```grain -coerceNumberToUint16 : Number -> Uint16 +coerceNumberToUint16 : (number: Number) -> Uint16 ``` Converts a Number to a Uint16. @@ -666,7 +668,7 @@ No other changes yet. ```grain -coerceNumberToInt32 : Number -> Int32 +coerceNumberToInt32 : (x: Number) -> Int32 ``` Converts a Number to an Int32. @@ -691,7 +693,7 @@ No other changes yet. ```grain -coerceNumberToInt64 : Number -> Int64 +coerceNumberToInt64 : (x: Number) -> Int64 ``` Converts a Number to an Int64. @@ -716,7 +718,7 @@ No other changes yet. ```grain -coerceNumberToBigInt : Number -> BigInt +coerceNumberToBigInt : (x: Number) -> BigInt ``` Converts a Number to a BigInt. @@ -741,7 +743,7 @@ No other changes yet. ```grain -coerceNumberToRational : Number -> Rational +coerceNumberToRational : (x: Number) -> Rational ``` Converts a Number to a Rational. @@ -766,7 +768,7 @@ No other changes yet. ```grain -coerceNumberToFloat32 : Number -> Float32 +coerceNumberToFloat32 : (x: Number) -> Float32 ``` Converts a Number to a Float32. @@ -791,7 +793,7 @@ No other changes yet. ```grain -coerceNumberToFloat64 : Number -> Float64 +coerceNumberToFloat64 : (x: Number) -> Float64 ``` Converts a Number to a Float64. @@ -816,7 +818,7 @@ No other changes yet. ```grain -coerceInt8ToNumber : Int8 -> Number +coerceInt8ToNumber : (value: Int8) -> Number ``` Converts an Int8 to a Number. @@ -841,7 +843,7 @@ No other changes yet. ```grain -coerceInt16ToNumber : Int16 -> Number +coerceInt16ToNumber : (value: Int16) -> Number ``` Converts an Int16 to a Number. @@ -866,7 +868,7 @@ No other changes yet. ```grain -coerceUint8ToNumber : Uint8 -> Number +coerceUint8ToNumber : (value: Uint8) -> Number ``` Converts a Uint8 to a Number. @@ -891,7 +893,7 @@ No other changes yet. ```grain -coerceUint16ToNumber : Uint16 -> Number +coerceUint16ToNumber : (value: Uint16) -> Number ``` Converts a Uint16 to a Number. @@ -916,7 +918,7 @@ No other changes yet. ```grain -coerceInt32ToNumber : Int32 -> Number +coerceInt32ToNumber : (x: Int32) -> Number ``` Converts an Int32 to a Number. @@ -941,7 +943,7 @@ No other changes yet. ```grain -coerceInt64ToNumber : Int64 -> Number +coerceInt64ToNumber : (x: Int64) -> Number ``` Converts an Int64 to a Number. @@ -966,7 +968,7 @@ No other changes yet. ```grain -coerceBigIntToNumber : BigInt -> Number +coerceBigIntToNumber : (x: BigInt) -> Number ``` Converts a BigInt to a Number. @@ -991,7 +993,7 @@ No other changes yet. ```grain -coerceRationalToNumber : Rational -> Number +coerceRationalToNumber : (x: Rational) -> Number ``` Converts a Rational to a Number. @@ -1016,7 +1018,7 @@ No other changes yet. ```grain -coerceFloat32ToNumber : Float32 -> Number +coerceFloat32ToNumber : (x: Float32) -> Number ``` Converts a Float32 to a Number. @@ -1041,7 +1043,7 @@ No other changes yet. ```grain -coerceFloat64ToNumber : Float64 -> Number +coerceFloat64ToNumber : (x: Float64) -> Number ``` Converts a Float64 to a Number. @@ -1061,13 +1063,13 @@ Returns: ### Numbers.**convertExactToInexact** ```grain -convertExactToInexact : Number -> Number +convertExactToInexact : (x: Number) -> Number ``` ### Numbers.**convertInexactToExact** ```grain -convertInexactToExact : Number -> Number +convertInexactToExact : (x: Number) -> Number ``` ### Numbers.**(+)** @@ -1078,7 +1080,7 @@ No other changes yet. ```grain -(+) : (Number, Number) -> Number +(+) : (x: Number, y: Number) -> Number ``` Computes the sum of its operands. @@ -1104,7 +1106,7 @@ No other changes yet. ```grain -(-) : (Number, Number) -> Number +(-) : (x: Number, y: Number) -> Number ``` Computes the difference of its operands. @@ -1130,7 +1132,7 @@ No other changes yet. ```grain -(*) : (Number, Number) -> Number +(*) : (x: Number, y: Number) -> Number ``` Computes the product of its operands. @@ -1156,7 +1158,7 @@ No other changes yet. ```grain -(/) : (Number, Number) -> Number +(/) : (x: Number, y: Number) -> Number ``` Computes the quotient of its operands. @@ -1182,7 +1184,7 @@ No other changes yet. ```grain -(%) : (Number, Number) -> Number +(%) : (x: Number, y: Number) -> Number ``` Computes the remainder of the division of the first operand by the second. @@ -1209,7 +1211,7 @@ No other changes yet. ```grain -incr : Number -> Number +incr : (x: Number) -> Number ``` Increments the value by one. @@ -1234,7 +1236,7 @@ No other changes yet. ```grain -decr : Number -> Number +decr : (x: Number) -> Number ``` Decrements the value by one. @@ -1254,7 +1256,7 @@ Returns: ### Numbers.**isBigInt** ```grain -isBigInt : a -> Bool +isBigInt : (x: a) -> Bool ``` ### Numbers.**scalbn** @@ -1265,7 +1267,7 @@ No other changes yet. ```grain -scalbn : (WasmF64, WasmI32) -> WasmF64 +scalbn : (x: WasmF64, n: WasmI32) -> WasmF64 ``` Multiplies a floating-point number by an integral power of 2. @@ -1298,7 +1300,7 @@ Returns: ```grain -(**) : (Number, Number) -> Number +(**) : (base: Number, power: Number) -> Number ``` Computes the exponentiation of the given base and power. diff --git a/stdlib/runtime/string.md b/stdlib/runtime/string.md index b9a6d9981b..f098bebf65 100644 --- a/stdlib/runtime/string.md +++ b/stdlib/runtime/string.md @@ -14,7 +14,7 @@ No other changes yet. ```grain -concat : (String, String) -> String +concat : (s1: String, s2: String) -> String ``` Concatenate two strings. @@ -46,7 +46,7 @@ No other changes yet. ```grain -toString : a -> String +toString : (value: a) -> String ``` Converts the given operand to a string. @@ -72,7 +72,7 @@ No other changes yet. ```grain -print : a -> Void +print : (value: a) -> Void ``` Prints the given operand to the console. Works for any type. Internally, calls `toString` diff --git a/stdlib/runtime/unsafe/conv.md b/stdlib/runtime/unsafe/conv.md index 6cc11458c5..8b3a4e56eb 100644 --- a/stdlib/runtime/unsafe/conv.md +++ b/stdlib/runtime/unsafe/conv.md @@ -9,79 +9,79 @@ Functions and constants included in the Conv module. ### Conv.**toInt32** ```grain -toInt32 : WasmI32 -> Int32 +toInt32 : (n: WasmI32) -> Int32 ``` ### Conv.**toUint32** ```grain -toUint32 : WasmI32 -> Uint32 +toUint32 : (n: WasmI32) -> Uint32 ``` ### Conv.**fromInt32** ```grain -fromInt32 : Int32 -> WasmI32 +fromInt32 : (n: Int32) -> WasmI32 ``` ### Conv.**fromUint32** ```grain -fromUint32 : Uint32 -> WasmI32 +fromUint32 : (n: Uint32) -> WasmI32 ``` ### Conv.**toInt64** ```grain -toInt64 : WasmI64 -> Int64 +toInt64 : (n: WasmI64) -> Int64 ``` ### Conv.**toUint64** ```grain -toUint64 : WasmI64 -> Uint64 +toUint64 : (n: WasmI64) -> Uint64 ``` ### Conv.**fromInt64** ```grain -fromInt64 : Int64 -> WasmI64 +fromInt64 : (n: Int64) -> WasmI64 ``` ### Conv.**fromUint64** ```grain -fromUint64 : Uint64 -> WasmI64 +fromUint64 : (n: Uint64) -> WasmI64 ``` ### Conv.**toFloat32** ```grain -toFloat32 : WasmF32 -> Float32 +toFloat32 : (n: WasmF32) -> Float32 ``` ### Conv.**fromFloat32** ```grain -fromFloat32 : Float32 -> WasmF32 +fromFloat32 : (n: Float32) -> WasmF32 ``` ### Conv.**toFloat64** ```grain -toFloat64 : WasmF64 -> Float64 +toFloat64 : (n: WasmF64) -> Float64 ``` ### Conv.**fromFloat64** ```grain -fromFloat64 : Float64 -> WasmF64 +fromFloat64 : (n: Float64) -> WasmF64 ``` ### Conv.**wasmI32ToNumber** ```grain -wasmI32ToNumber : WasmI32 -> Number +wasmI32ToNumber : (n: WasmI32) -> Number ``` Converts a WasmI32 value to Number. diff --git a/stdlib/runtime/unsafe/memory.md b/stdlib/runtime/unsafe/memory.md index 23b12291a0..dd7ddb7da0 100644 --- a/stdlib/runtime/unsafe/memory.md +++ b/stdlib/runtime/unsafe/memory.md @@ -9,37 +9,37 @@ Functions and constants included in the Memory module. ### Memory.**malloc** ```grain -malloc : WasmI32 -> WasmI32 +malloc : (size: WasmI32) -> WasmI32 ``` ### Memory.**free** ```grain -free : WasmI32 -> Void +free : (userPtr: WasmI32) -> Void ``` ### Memory.**incRef** ```grain -incRef : WasmI32 -> WasmI32 +incRef : (userPtr: WasmI32) -> WasmI32 ``` ### Memory.**decRef** ```grain -decRef : WasmI32 -> WasmI32 +decRef : (userPtr: WasmI32) -> WasmI32 ``` ### Memory.**copy** ```grain -copy : (WasmI32, WasmI32, WasmI32) -> Void +copy : (dest: WasmI32, src: WasmI32, n: WasmI32) -> Void ``` ### Memory.**fill** ```grain -fill : (WasmI32, WasmI32, WasmI32) -> Void +fill : (dest: WasmI32, c: WasmI32, n: WasmI32) -> Void ``` ### Memory.**compare** diff --git a/stdlib/runtime/utils/printing.md b/stdlib/runtime/utils/printing.md index ac5bb02f3a..3aefd3376f 100644 --- a/stdlib/runtime/utils/printing.md +++ b/stdlib/runtime/utils/printing.md @@ -9,18 +9,18 @@ Functions and constants included in the Printing module. ### Printing.**numberToString** ```grain -numberToString : WasmI64 -> String +numberToString : (n: WasmI64) -> String ``` ### Printing.**printNumber** ```grain -printNumber : WasmI64 -> Void +printNumber : (n: WasmI64) -> Void ``` ### Printing.**printString** ```grain -printString : String -> Void +printString : (s: String) -> Void ``` diff --git a/stdlib/runtime/wasi.md b/stdlib/runtime/wasi.md index daf511dc54..de13f2e544 100644 --- a/stdlib/runtime/wasi.md +++ b/stdlib/runtime/wasi.md @@ -842,6 +842,6 @@ _ENOTCAPABLE : WasmI32 ### Wasi.**stringOfSystemError** ```grain -stringOfSystemError : a -> String +stringOfSystemError : (code: a) -> String ``` diff --git a/stdlib/set.md b/stdlib/set.md index c0f822ffbd..b6873cf3a7 100644 --- a/stdlib/set.md +++ b/stdlib/set.md @@ -35,7 +35,7 @@ No other changes yet. ```grain -makeSized : Number -> Set +makeSized : (size: Number) -> Set ``` Creates a new empty set with an initial storage of the given size. As values are added or removed, the internal storage may grow or shrink. Generally, you won't need to care about the storage size of your set and can use `Set.make()` instead. @@ -79,7 +79,7 @@ No other changes yet. ```grain -add : (a, Set) -> Void +add : (key: a, set: Set) -> Void ``` Adds a new value to the set. If the value already exists, nothing happens. @@ -99,7 +99,7 @@ No other changes yet. ```grain -contains : (a, Set) -> Bool +contains : (key: a, set: Set) -> Bool ``` Determines if the set contains the given value. @@ -125,7 +125,7 @@ No other changes yet. ```grain -remove : (a, Set) -> Void +remove : (key: a, set: Set) -> Void ``` Removes the given value from the set. If the value doesn't exist, nothing happens. @@ -145,7 +145,7 @@ No other changes yet. ```grain -size : Set -> Number +size : (set: Set) -> Number ``` Provides the count of values within the set. @@ -170,7 +170,7 @@ No other changes yet. ```grain -isEmpty : Set -> Bool +isEmpty : (set: Set) -> Bool ``` Determines if the set contains no elements. @@ -195,7 +195,7 @@ No other changes yet. ```grain -clear : Set -> Void +clear : (set: Set) -> Void ``` Resets the set by removing all values. @@ -221,7 +221,7 @@ Parameters: ```grain -forEach : ((a -> Void), Set) -> Void +forEach : (fn: (a -> Void), set: Set) -> Void ``` Iterates the set, calling an iterator function on each element. @@ -241,7 +241,7 @@ No other changes yet. ```grain -reduce : (((a, b) -> a), a, Set) -> a +reduce : (fn: ((a, b) -> a), init: a, set: Set) -> a ``` Combines all elements of a set using a reducer function. @@ -268,7 +268,7 @@ No other changes yet. ```grain -filter : ((a -> Bool), Set) -> Void +filter : (fn: (a -> Bool), set: Set) -> Void ``` Removes elements from a set where a predicate function returns `false`. @@ -288,7 +288,7 @@ No other changes yet. ```grain -reject : ((a -> Bool), Set) -> Void +reject : (fn: (a -> Bool), set: Set) -> Void ``` Removes elements from a set where a predicate function returns `true`. @@ -308,7 +308,7 @@ No other changes yet. ```grain -toList : Set -> List +toList : (set: Set) -> List ``` Converts a set into a list of its elements. @@ -333,7 +333,7 @@ No other changes yet. ```grain -fromList : List -> Set +fromList : (list: List) -> Set ``` Creates a set from a list. @@ -358,7 +358,7 @@ No other changes yet. ```grain -toArray : Set -> Array +toArray : (set: Set) -> Array ``` Converts a set into an array of its elements. @@ -383,7 +383,7 @@ No other changes yet. ```grain -fromArray : Array -> Set +fromArray : (array: Array) -> Set ``` Creates a set from an array. @@ -408,7 +408,7 @@ No other changes yet. ```grain -union : (Set, Set) -> Set +union : (set1: Set, set2: Set) -> Set ``` Combines two sets into a single set containing all elements from both sets. @@ -434,7 +434,7 @@ No other changes yet. ```grain -diff : (Set, Set) -> Set +diff : (set1: Set, set2: Set) -> Set ``` Combines two sets into a single set containing only the elements not shared between both sets. @@ -460,7 +460,7 @@ No other changes yet. ```grain -intersect : (Set, Set) -> Set +intersect : (set1: Set, set2: Set) -> Set ``` Combines two sets into a single set containing only the elements shared between both sets. @@ -486,7 +486,7 @@ No other changes yet. ```grain -getInternalStats : Set -> (Number, Number) +getInternalStats : (set: Set) -> (Number, Number) ``` Provides data representing the internal state state of the set. diff --git a/stdlib/stack.md b/stdlib/stack.md index 686efc55a6..03584802e0 100644 --- a/stdlib/stack.md +++ b/stdlib/stack.md @@ -41,7 +41,7 @@ No other changes yet. ```grain -makeSized : Number -> Stack +makeSized : (size: Number) -> Stack ``` Creates a new stack with an initial storage of the given size. As values are @@ -88,7 +88,7 @@ No other changes yet. ```grain -isEmpty : Stack -> Bool +isEmpty : (stack: Stack) -> Bool ``` Checks if the given stack contains no items. @@ -113,7 +113,7 @@ No other changes yet. ```grain -size : Stack -> Number +size : (stack: Stack) -> Number ``` Computes the size of the input stack. @@ -138,7 +138,7 @@ No other changes yet. ```grain -peek : Stack -> Option +peek : (stack: Stack) -> Option ``` Provides the value at the top of the stack, if it exists. @@ -163,7 +163,7 @@ No other changes yet. ```grain -push : (a, Stack) -> Void +push : (value: a, stack: Stack) -> Void ``` Adds a new item to the top of the stack. @@ -183,7 +183,7 @@ No other changes yet. ```grain -pop : Stack -> Option +pop : (stack: Stack) -> Option ``` Removes the item at the top of the stack. @@ -208,7 +208,7 @@ No other changes yet. ```grain -clear : Stack -> Void +clear : (stack: Stack) -> Void ``` Clears the stack by removing all of its elements @@ -227,7 +227,7 @@ No other changes yet. ```grain -copy : Stack -> Stack +copy : (stack: Stack) -> Stack ``` Produces a shallow copy of the input stack. @@ -299,7 +299,7 @@ An empty stack. ```grain -isEmpty : ImmutableStack -> Bool +isEmpty : (stack: ImmutableStack) -> Bool ``` Checks if the given stack contains no items. @@ -332,7 +332,7 @@ Returns: ```grain -peek : ImmutableStack -> Option +peek : (stack: ImmutableStack) -> Option ``` Provides the value at the top of the stack, if it exists. @@ -364,7 +364,7 @@ Returns: ```grain -push : (a, ImmutableStack) -> ImmutableStack +push : (value: a, stack: ImmutableStack) -> ImmutableStack ``` Adds a new item to the top of the stack. @@ -397,7 +397,7 @@ Returns: ```grain -pop : ImmutableStack -> ImmutableStack +pop : (stack: ImmutableStack) -> ImmutableStack ``` Removes the item at the top of the stack. @@ -429,7 +429,7 @@ Returns: ```grain -size : ImmutableStack -> Number +size : (stack: ImmutableStack) -> Number ``` Computes the size of the input stack. diff --git a/stdlib/string.md b/stdlib/string.md index 9a40b1bf78..81b78cceba 100644 --- a/stdlib/string.md +++ b/stdlib/string.md @@ -51,7 +51,7 @@ No other changes yet. ```grain -concat : (String, String) -> String +concat : (s1: String, s2: String) -> String ``` Concatenate two strings. @@ -83,7 +83,7 @@ No other changes yet. ```grain -length : String -> Number +length : (string: String) -> Number ``` Returns the character length of the input string. @@ -114,7 +114,7 @@ No other changes yet. ```grain -byteLength : String -> Number +byteLength : (string: String) -> Number ``` Returns the byte length of the input string. @@ -145,7 +145,7 @@ No other changes yet. ```grain -indexOf : (String, String) -> Option +indexOf : (search: String, string: String) -> Option ``` Finds the first position of a substring in the input string. @@ -177,7 +177,7 @@ No other changes yet. ```grain -lastIndexOf : (String, String) -> Option +lastIndexOf : (search: String, string: String) -> Option ``` Finds the last position of a substring in the input string. @@ -209,7 +209,7 @@ No other changes yet. ```grain -charCodeAt : (Number, String) -> Number +charCodeAt : (position: Number, string: String) -> Number ``` Get the Unicode code point at the position in the input string. @@ -251,7 +251,7 @@ No other changes yet. ```grain -charAt : (Number, String) -> Char +charAt : (position: Number, string: String) -> Char ``` Get the character at the position in the input string. @@ -293,7 +293,7 @@ No other changes yet. ```grain -explode : String -> Array +explode : (string: String) -> Array ``` Split a string into its Unicode characters. @@ -330,7 +330,7 @@ No other changes yet. ```grain -implode : Array -> String +implode : (arr: Array) -> String ``` Create a string from an array of characters. @@ -361,7 +361,7 @@ No other changes yet. ```grain -reverse : String -> String +reverse : (string: String) -> String ``` Create a string that is the given string reversed. @@ -387,7 +387,7 @@ String.reverse("olleH") == "Hello" ### String.**split** ```grain -split : (String, String) -> Array +split : (separator: String, string: String) -> Array ``` Split a string by the given separator. @@ -425,7 +425,7 @@ No other changes yet. ```grain -slice : (Number, Number, String) -> String +slice : (start: Number, to: Number, string: String) -> String ``` Get a portion of a string. @@ -471,7 +471,7 @@ No other changes yet. ```grain -contains : (String, String) -> Bool +contains : (search: String, string: String) -> Bool ``` Check if a string contains a substring. @@ -503,7 +503,7 @@ No other changes yet. ```grain -startsWith : (String, String) -> Bool +startsWith : (search: String, string: String) -> Bool ``` Check if a string begins with another string. @@ -535,7 +535,7 @@ No other changes yet. ```grain -endsWith : (String, String) -> Bool +endsWith : (search: String, string: String) -> Bool ``` Check if a string ends with another string. @@ -567,7 +567,8 @@ No other changes yet. ```grain -replaceFirst : (String, String, String) -> String +replaceFirst : + (searchPattern: String, replacement: String, string: String) -> String ``` Replaces the first appearance of the search pattern in the string with the replacement value. @@ -600,7 +601,8 @@ No other changes yet. ```grain -replaceLast : (String, String, String) -> String +replaceLast : + (searchPattern: String, replacement: String, string: String) -> String ``` Replaces the last appearance of the search pattern in the string with the replacement value. @@ -633,7 +635,8 @@ No other changes yet. ```grain -replaceAll : (String, String, String) -> String +replaceAll : + (searchPattern: String, replacement: String, string: String) -> String ``` Replaces every appearance of the search pattern in the string with the replacement value. @@ -666,7 +669,8 @@ No other changes yet. ```grain -encodeAt : (String, Encoding, Bytes, Number) -> Bytes +encodeAt : + (string: String, encoding: Encoding, dest: Bytes, destPos: Number) -> Bytes ``` Encodes the given string into a byte sequence at the supplied position, excluding any byte-order marker, using the encoding scheme provided. @@ -701,7 +705,8 @@ No other changes yet. ```grain -encodeAtWithBom : (String, Encoding, Bytes, Number) -> Bytes +encodeAtWithBom : + (string: String, encoding: Encoding, dest: Bytes, destPos: Number) -> Bytes ``` Encodes the given string into a byte sequence at the supplied position, including any byte-order marker, using the encoding scheme provided. @@ -736,7 +741,7 @@ No other changes yet. ```grain -encode : (String, Encoding) -> Bytes +encode : (string: String, encoding: Encoding) -> Bytes ``` Encodes the given string using the given encoding scheme, excluding any byte-order marker. @@ -762,7 +767,7 @@ No other changes yet. ```grain -encodeWithBom : (String, Encoding) -> Bytes +encodeWithBom : (string: String, encoding: Encoding) -> Bytes ``` Encodes the given string using the given encoding scheme, including any byte-order marker. @@ -788,7 +793,8 @@ No other changes yet. ```grain -decodeRange : (Bytes, Encoding, Number, Number) -> String +decodeRange : + (bytes: Bytes, encoding: Encoding, start: Number, size: Number) -> String ``` Decodes the given byte sequence of the specified range into a string, excluding any byte-order marker, using encoding scheme provided. @@ -825,7 +831,8 @@ No other changes yet. ```grain -decodeRangeKeepBom : (Bytes, Encoding, Number, Number) -> String +decodeRangeKeepBom : + (bytes: Bytes, encoding: Encoding, start: Number, size: Number) -> String ``` Decodes the given byte sequence of the specified range into a string, including any byte-order marker, using encoding scheme provided. @@ -862,7 +869,7 @@ No other changes yet. ```grain -decode : (Bytes, Encoding) -> String +decode : (bytes: Bytes, encoding: Encoding) -> String ``` Decodes the given byte sequence into a string using the given encoding scheme, excluding any byte-order marker. @@ -888,7 +895,7 @@ No other changes yet. ```grain -decodeKeepBom : (Bytes, Encoding) -> String +decodeKeepBom : (bytes: Bytes, encoding: Encoding) -> String ``` Decodes the given byte sequence into a string using the given encoding scheme, including any byte-order marker. @@ -914,7 +921,7 @@ No other changes yet. ```grain -forEachCodePoint : ((Number -> Void), String) -> Void +forEachCodePoint : (fn: (Number -> Void), str: String) -> Void ``` Iterates over Unicode code points in a string. @@ -940,7 +947,7 @@ No other changes yet. ```grain -forEachCodePointi : (((Number, Number) -> Void), String) -> Void +forEachCodePointi : (fn: ((Number, Number) -> Void), str: String) -> Void ``` Iterates over Unicode code points in a string. This is the same as @@ -968,7 +975,7 @@ No other changes yet. ```grain -trimStart : String -> String +trimStart : (string: String) -> String ``` Trims the beginning of a string—removing any leading whitespace characters. @@ -999,7 +1006,7 @@ No other changes yet. ```grain -trimEnd : String -> String +trimEnd : (string: String) -> String ``` Trims the end of a string—removing any trailing whitespace characters. @@ -1030,7 +1037,7 @@ No other changes yet. ```grain -trim : String -> String +trim : (string: String) -> String ``` Trims a string—removing all leading and trailing whitespace characters. diff --git a/stdlib/sys/file.md b/stdlib/sys/file.md index 336e6b0801..9032bff3f9 100644 --- a/stdlib/sys/file.md +++ b/stdlib/sys/file.md @@ -211,8 +211,10 @@ The `FileDescriptor` for the current working directory of the process. ```grain pathOpen : - (FileDescriptor, List, String, List, List, - List, List) -> Result + (dirFd: FileDescriptor, dirFlags: List, path: String, + openFlags: List, rights: List, + rightsInheriting: List, flags: List) -> + Result ``` Open a file or directory. @@ -238,7 +240,8 @@ Returns: ### File.**fdRead** ```grain -fdRead : (FileDescriptor, Number) -> Result<(Bytes, Number), Exception> +fdRead : + (fd: FileDescriptor, size: Number) -> Result<(Bytes, Number), Exception> ``` Read from a file descriptor. @@ -260,7 +263,8 @@ Returns: ```grain fdPread : - (FileDescriptor, Int64, Number) -> Result<(Bytes, Number), Exception> + (fd: FileDescriptor, offset: Int64, size: Number) -> + Result<(Bytes, Number), Exception> ``` Read from a file descriptor without updating the file descriptor's offset. @@ -282,7 +286,7 @@ Returns: ### File.**fdWrite** ```grain -fdWrite : (FileDescriptor, Bytes) -> Result +fdWrite : (fd: FileDescriptor, data: Bytes) -> Result ``` Write to a file descriptor. @@ -303,7 +307,9 @@ Returns: ### File.**fdPwrite** ```grain -fdPwrite : (FileDescriptor, Bytes, Int64) -> Result +fdPwrite : + (fd: FileDescriptor, data: Bytes, offset: Int64) -> + Result ``` Write to a file descriptor without updating the file descriptor's offset. @@ -325,7 +331,8 @@ Returns: ### File.**fdAllocate** ```grain -fdAllocate : (FileDescriptor, Int64, Int64) -> Result +fdAllocate : + (fd: FileDescriptor, offset: Int64, size: Int64) -> Result ``` Allocate space within a file. @@ -347,7 +354,7 @@ Returns: ### File.**fdClose** ```grain -fdClose : FileDescriptor -> Result +fdClose : (fd: FileDescriptor) -> Result ``` Close a file descriptor. @@ -367,7 +374,7 @@ Returns: ### File.**fdDatasync** ```grain -fdDatasync : FileDescriptor -> Result +fdDatasync : (fd: FileDescriptor) -> Result ``` Synchronize the data of a file to disk. @@ -387,7 +394,7 @@ Returns: ### File.**fdSync** ```grain -fdSync : FileDescriptor -> Result +fdSync : (fd: FileDescriptor) -> Result ``` Synchronize the data and metadata of a file to disk. @@ -407,7 +414,7 @@ Returns: ### File.**fdStats** ```grain -fdStats : FileDescriptor -> Result +fdStats : (fd: FileDescriptor) -> Result ``` Retrieve information about a file descriptor. @@ -427,7 +434,8 @@ Returns: ### File.**fdSetFlags** ```grain -fdSetFlags : (FileDescriptor, List) -> Result +fdSetFlags : + (fd: FileDescriptor, flags: List) -> Result ``` Update the flags associated with a file descriptor. @@ -449,7 +457,8 @@ Returns: ```grain fdSetRights : - (FileDescriptor, List, List) -> Result + (fd: FileDescriptor, rights: List, rightsInheriting: List) -> + Result ``` Update the rights associated with a file descriptor. @@ -471,7 +480,7 @@ Returns: ### File.**fdFilestats** ```grain -fdFilestats : FileDescriptor -> Result +fdFilestats : (fd: FileDescriptor) -> Result ``` Retrieve information about a file. @@ -491,7 +500,7 @@ Returns: ### File.**fdSetSize** ```grain -fdSetSize : (FileDescriptor, Int64) -> Result +fdSetSize : (fd: FileDescriptor, size: Int64) -> Result ``` Set (truncate) the size of a file. @@ -512,7 +521,8 @@ Returns: ### File.**fdSetAccessTime** ```grain -fdSetAccessTime : (FileDescriptor, Int64) -> Result +fdSetAccessTime : + (fd: FileDescriptor, timestamp: Int64) -> Result ``` Set the access (created) time of a file. @@ -533,7 +543,7 @@ Returns: ### File.**fdSetAccessTimeNow** ```grain -fdSetAccessTimeNow : FileDescriptor -> Result +fdSetAccessTimeNow : (fd: FileDescriptor) -> Result ``` Set the access (created) time of a file to the current time. @@ -553,7 +563,8 @@ Returns: ### File.**fdSetModifiedTime** ```grain -fdSetModifiedTime : (FileDescriptor, Int64) -> Result +fdSetModifiedTime : + (fd: FileDescriptor, timestamp: Int64) -> Result ``` Set the modified time of a file. @@ -574,7 +585,7 @@ Returns: ### File.**fdSetModifiedTimeNow** ```grain -fdSetModifiedTimeNow : FileDescriptor -> Result +fdSetModifiedTimeNow : (fd: FileDescriptor) -> Result ``` Set the modified time of a file to the current time. @@ -594,7 +605,7 @@ Returns: ### File.**fdReaddir** ```grain -fdReaddir : FileDescriptor -> Result, Exception> +fdReaddir : (fd: FileDescriptor) -> Result, Exception> ``` Read the entires of a directory. @@ -614,7 +625,8 @@ Returns: ### File.**fdRenumber** ```grain -fdRenumber : (FileDescriptor, FileDescriptor) -> Result +fdRenumber : + (fromFd: FileDescriptor, toFd: FileDescriptor) -> Result ``` Atomically replace a file descriptor by renumbering another file descriptor. @@ -635,7 +647,9 @@ Returns: ### File.**fdSeek** ```grain -fdSeek : (FileDescriptor, Int64, Whence) -> Result +fdSeek : + (fd: FileDescriptor, offset: Int64, whence: Whence) -> + Result ``` Update a file descriptor's offset. @@ -657,7 +671,7 @@ Returns: ### File.**fdTell** ```grain -fdTell : FileDescriptor -> Result +fdTell : (fd: FileDescriptor) -> Result ``` Read a file descriptor's offset. @@ -677,7 +691,8 @@ Returns: ### File.**pathCreateDirectory** ```grain -pathCreateDirectory : (FileDescriptor, String) -> Result +pathCreateDirectory : + (fd: FileDescriptor, path: String) -> Result ``` Create a directory. @@ -699,7 +714,8 @@ Returns: ```grain pathFilestats : - (FileDescriptor, List, String) -> Result + (fd: FileDescriptor, dirFlags: List, path: String) -> + Result ``` Retrieve information about a file. @@ -722,8 +738,8 @@ Returns: ```grain pathSetAccessTime : - (FileDescriptor, List, String, Int64) -> - Result + (fd: FileDescriptor, dirFlags: List, path: String, + timestamp: Int64) -> Result ``` Set the access (created) time of a file. @@ -747,7 +763,8 @@ Returns: ```grain pathSetAccessTimeNow : - (FileDescriptor, List, String) -> Result + (fd: FileDescriptor, dirFlags: List, path: String) -> + Result ``` Set the access (created) time of a file to the current time. @@ -770,8 +787,8 @@ Returns: ```grain pathSetModifiedTime : - (FileDescriptor, List, String, Int64) -> - Result + (fd: FileDescriptor, dirFlags: List, path: String, + timestamp: Int64) -> Result ``` Set the modified time of a file. @@ -795,7 +812,8 @@ Returns: ```grain pathSetModifiedTimeNow : - (FileDescriptor, List, String) -> Result + (fd: FileDescriptor, dirFlags: List, path: String) -> + Result ``` Set the modified time of a file to the current time. @@ -818,7 +836,8 @@ Returns: ```grain pathLink : - (FileDescriptor, List, String, FileDescriptor, String) -> + (sourceFd: FileDescriptor, dirFlags: List, sourcePath: + String, targetFd: FileDescriptor, targetPath: String) -> Result ``` @@ -843,7 +862,9 @@ Returns: ### File.**pathSymlink** ```grain -pathSymlink : (FileDescriptor, String, String) -> Result +pathSymlink : + (fd: FileDescriptor, sourcePath: String, targetPath: String) -> + Result ``` Create a symlink. @@ -865,7 +886,7 @@ Returns: ### File.**pathUnlink** ```grain -pathUnlink : (FileDescriptor, String) -> Result +pathUnlink : (fd: FileDescriptor, path: String) -> Result ``` Unlink a file. @@ -887,7 +908,8 @@ Returns: ```grain pathReadlink : - (FileDescriptor, String, Number) -> Result<(String, Number), Exception> + (fd: FileDescriptor, path: String, size: Number) -> + Result<(String, Number), Exception> ``` Read the contents of a symbolic link. @@ -909,7 +931,8 @@ Returns: ### File.**pathRemoveDirectory** ```grain -pathRemoveDirectory : (FileDescriptor, String) -> Result +pathRemoveDirectory : + (fd: FileDescriptor, path: String) -> Result ``` Remove a directory. @@ -931,7 +954,8 @@ Returns: ```grain pathRename : - (FileDescriptor, String, FileDescriptor, String) -> Result + (sourceFd: FileDescriptor, sourcePath: String, targetFd: FileDescriptor, + targetPath: String) -> Result ``` Rename a file or directory. diff --git a/stdlib/sys/process.md b/stdlib/sys/process.md index 7880f48d96..35f25279d0 100644 --- a/stdlib/sys/process.md +++ b/stdlib/sys/process.md @@ -88,7 +88,7 @@ Returns: ### Process.**exit** ```grain -exit : Number -> Result +exit : (code: Number) -> Result ``` Terminate the process normally. @@ -108,7 +108,7 @@ Returns: ### Process.**sigRaise** ```grain -sigRaise : Signal -> Result +sigRaise : (signalPtr: Signal) -> Result ``` Send a signal to the process of the calling thread. diff --git a/stdlib/uint16.md b/stdlib/uint16.md index 437417ad84..79000c1b12 100644 --- a/stdlib/uint16.md +++ b/stdlib/uint16.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Uint16 +fromNumber : (number: Number) -> Uint16 ``` Converts a Number to a Uint16. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Uint16 -> Number +toNumber : (value: Uint16) -> Number ``` Converts a Uint16 to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -fromInt16 : Int16 -> Uint16 +fromInt16 : (x: Int16) -> Uint16 ``` Converts an Int16 to a Uint16. @@ -100,7 +100,7 @@ No other changes yet. ```grain -incr : Uint16 -> Uint16 +incr : (value: Uint16) -> Uint16 ``` Increments the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -decr : Uint16 -> Uint16 +decr : (value: Uint16) -> Uint16 ``` Decrements the value by one. @@ -150,7 +150,7 @@ No other changes yet. ```grain -(+) : (Uint16, Uint16) -> Uint16 +(+) : (x: Uint16, y: Uint16) -> Uint16 ``` Computes the sum of its operands. @@ -176,7 +176,7 @@ No other changes yet. ```grain -(-) : (Uint16, Uint16) -> Uint16 +(-) : (x: Uint16, y: Uint16) -> Uint16 ``` Computes the difference of its operands. @@ -202,7 +202,7 @@ No other changes yet. ```grain -(*) : (Uint16, Uint16) -> Uint16 +(*) : (x: Uint16, y: Uint16) -> Uint16 ``` Computes the product of its operands. @@ -228,7 +228,7 @@ No other changes yet. ```grain -(/) : (Uint16, Uint16) -> Uint16 +(/) : (x: Uint16, y: Uint16) -> Uint16 ``` Computes the quotient of its operands. @@ -254,7 +254,7 @@ No other changes yet. ```grain -rem : (Uint16, Uint16) -> Uint16 +rem : (x: Uint16, y: Uint16) -> Uint16 ``` Computes the remainder of the division of its operands. @@ -280,7 +280,7 @@ No other changes yet. ```grain -(<<) : (Uint16, Uint16) -> Uint16 +(<<) : (value: Uint16, amount: Uint16) -> Uint16 ``` Shifts the bits of the value left by the given number of bits. @@ -306,7 +306,7 @@ No other changes yet. ```grain -(>>>) : (Uint16, Uint16) -> Uint16 +(>>>) : (value: Uint16, amount: Uint16) -> Uint16 ``` Shifts the bits of the value right by the given number of bits. @@ -332,7 +332,7 @@ No other changes yet. ```grain -(==) : (Uint16, Uint16) -> Bool +(==) : (x: Uint16, y: Uint16) -> Bool ``` Checks if the first value is equal to the second value. @@ -358,7 +358,7 @@ No other changes yet. ```grain -(!=) : (Uint16, Uint16) -> Bool +(!=) : (x: Uint16, y: Uint16) -> Bool ``` Checks if the first value is not equal to the second value. @@ -384,7 +384,7 @@ No other changes yet. ```grain -(<) : (Uint16, Uint16) -> Bool +(<) : (x: Uint16, y: Uint16) -> Bool ``` Checks if the first value is less than the second value. @@ -410,7 +410,7 @@ No other changes yet. ```grain -(>) : (Uint16, Uint16) -> Bool +(>) : (x: Uint16, y: Uint16) -> Bool ``` Checks if the first value is greater than the second value. @@ -436,7 +436,7 @@ No other changes yet. ```grain -(<=) : (Uint16, Uint16) -> Bool +(<=) : (x: Uint16, y: Uint16) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -462,7 +462,7 @@ No other changes yet. ```grain -(>=) : (Uint16, Uint16) -> Bool +(>=) : (x: Uint16, y: Uint16) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -488,7 +488,7 @@ No other changes yet. ```grain -lnot : Uint16 -> Uint16 +lnot : (value: Uint16) -> Uint16 ``` Computes the bitwise NOT of the given value. @@ -513,7 +513,7 @@ No other changes yet. ```grain -(&) : (Uint16, Uint16) -> Uint16 +(&) : (x: Uint16, y: Uint16) -> Uint16 ``` Computes the bitwise AND (`&`) on the given operands. @@ -539,7 +539,7 @@ No other changes yet. ```grain -(|) : (Uint16, Uint16) -> Uint16 +(|) : (x: Uint16, y: Uint16) -> Uint16 ``` Computes the bitwise OR (`|`) on the given operands. @@ -565,7 +565,7 @@ No other changes yet. ```grain -(^) : (Uint16, Uint16) -> Uint16 +(^) : (x: Uint16, y: Uint16) -> Uint16 ``` Computes the bitwise XOR (`^`) on the given operands. diff --git a/stdlib/uint32.md b/stdlib/uint32.md index 052c120848..51921e048a 100644 --- a/stdlib/uint32.md +++ b/stdlib/uint32.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Uint32 +fromNumber : (x: Number) -> Uint32 ``` Converts a Number to a Uint32. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Uint32 -> Number +toNumber : (x: Uint32) -> Number ``` Converts a Uint32 to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -fromInt32 : Int32 -> Uint32 +fromInt32 : (x: Int32) -> Uint32 ``` Converts an Int32 to a Uint32. @@ -100,7 +100,7 @@ No other changes yet. ```grain -incr : Uint32 -> Uint32 +incr : (value: Uint32) -> Uint32 ``` Increments the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -decr : Uint32 -> Uint32 +decr : (value: Uint32) -> Uint32 ``` Decrements the value by one. @@ -150,7 +150,7 @@ No other changes yet. ```grain -(+) : (Uint32, Uint32) -> Uint32 +(+) : (x: Uint32, y: Uint32) -> Uint32 ``` Computes the sum of its operands. @@ -176,7 +176,7 @@ No other changes yet. ```grain -(-) : (Uint32, Uint32) -> Uint32 +(-) : (x: Uint32, y: Uint32) -> Uint32 ``` Computes the difference of its operands. @@ -202,7 +202,7 @@ No other changes yet. ```grain -(*) : (Uint32, Uint32) -> Uint32 +(*) : (x: Uint32, y: Uint32) -> Uint32 ``` Computes the product of its operands. @@ -228,7 +228,7 @@ No other changes yet. ```grain -(/) : (Uint32, Uint32) -> Uint32 +(/) : (x: Uint32, y: Uint32) -> Uint32 ``` Computes the quotient of its operands. @@ -254,7 +254,7 @@ No other changes yet. ```grain -rem : (Uint32, Uint32) -> Uint32 +rem : (x: Uint32, y: Uint32) -> Uint32 ``` Computes the remainder of the division of its operands. @@ -280,7 +280,7 @@ No other changes yet. ```grain -rotl : (Uint32, Uint32) -> Uint32 +rotl : (value: Uint32, amount: Uint32) -> Uint32 ``` Rotates the bits of the value left by the given number of bits. @@ -306,7 +306,7 @@ No other changes yet. ```grain -rotr : (Uint32, Uint32) -> Uint32 +rotr : (value: Uint32, amount: Uint32) -> Uint32 ``` Rotates the bits of the value right by the given number of bits. @@ -332,7 +332,7 @@ No other changes yet. ```grain -(<<) : (Uint32, Uint32) -> Uint32 +(<<) : (value: Uint32, amount: Uint32) -> Uint32 ``` Shifts the bits of the value left by the given number of bits. @@ -358,7 +358,7 @@ No other changes yet. ```grain -(>>>) : (Uint32, Uint32) -> Uint32 +(>>>) : (value: Uint32, amount: Uint32) -> Uint32 ``` Shifts the bits of the value right by the given number of bits. @@ -384,7 +384,7 @@ No other changes yet. ```grain -(==) : (Uint32, Uint32) -> Bool +(==) : (x: Uint32, y: Uint32) -> Bool ``` Checks if the first value is equal to the second value. @@ -410,7 +410,7 @@ No other changes yet. ```grain -(!=) : (Uint32, Uint32) -> Bool +(!=) : (x: Uint32, y: Uint32) -> Bool ``` Checks if the first value is not equal to the second value. @@ -436,7 +436,7 @@ No other changes yet. ```grain -eqz : Uint32 -> Bool +eqz : (value: Uint32) -> Bool ``` Checks if the given value is equal to zero. @@ -461,7 +461,7 @@ No other changes yet. ```grain -(<) : (Uint32, Uint32) -> Bool +(<) : (x: Uint32, y: Uint32) -> Bool ``` Checks if the first value is less than the second value. @@ -487,7 +487,7 @@ No other changes yet. ```grain -(>) : (Uint32, Uint32) -> Bool +(>) : (x: Uint32, y: Uint32) -> Bool ``` Checks if the first value is greater than the second value. @@ -513,7 +513,7 @@ No other changes yet. ```grain -(<=) : (Uint32, Uint32) -> Bool +(<=) : (x: Uint32, y: Uint32) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -539,7 +539,7 @@ No other changes yet. ```grain -(>=) : (Uint32, Uint32) -> Bool +(>=) : (x: Uint32, y: Uint32) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -565,7 +565,7 @@ No other changes yet. ```grain -lnot : Uint32 -> Uint32 +lnot : (value: Uint32) -> Uint32 ``` Computes the bitwise NOT of the given value. @@ -590,7 +590,7 @@ No other changes yet. ```grain -(&) : (Uint32, Uint32) -> Uint32 +(&) : (x: Uint32, y: Uint32) -> Uint32 ``` Computes the bitwise AND (`&`) on the given operands. @@ -616,7 +616,7 @@ No other changes yet. ```grain -(|) : (Uint32, Uint32) -> Uint32 +(|) : (x: Uint32, y: Uint32) -> Uint32 ``` Computes the bitwise OR (`|`) on the given operands. @@ -642,7 +642,7 @@ No other changes yet. ```grain -(^) : (Uint32, Uint32) -> Uint32 +(^) : (x: Uint32, y: Uint32) -> Uint32 ``` Computes the bitwise XOR (`^`) on the given operands. @@ -668,7 +668,7 @@ No other changes yet. ```grain -clz : Uint32 -> Uint32 +clz : (value: Uint32) -> Uint32 ``` Counts the number of leading zero bits in the value. @@ -693,7 +693,7 @@ No other changes yet. ```grain -ctz : Uint32 -> Uint32 +ctz : (value: Uint32) -> Uint32 ``` Counts the number of trailing zero bits in the value. @@ -718,7 +718,7 @@ No other changes yet. ```grain -popcnt : Uint32 -> Uint32 +popcnt : (value: Uint32) -> Uint32 ``` Counts the number of bits set to `1` in the value, also known as a population count. diff --git a/stdlib/uint64.md b/stdlib/uint64.md index ee27877f1f..2ac5565044 100644 --- a/stdlib/uint64.md +++ b/stdlib/uint64.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Uint64 +fromNumber : (x: Number) -> Uint64 ``` Converts a Number to a Uint64. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Uint64 -> Number +toNumber : (x: Uint64) -> Number ``` Converts a Uint64 to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -fromInt64 : Int64 -> Uint64 +fromInt64 : (x: Int64) -> Uint64 ``` Converts an Int64 to a Uint64. @@ -100,7 +100,7 @@ No other changes yet. ```grain -incr : Uint64 -> Uint64 +incr : (value: Uint64) -> Uint64 ``` Increments the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -decr : Uint64 -> Uint64 +decr : (value: Uint64) -> Uint64 ``` Decrements the value by one. @@ -150,7 +150,7 @@ No other changes yet. ```grain -(+) : (Uint64, Uint64) -> Uint64 +(+) : (x: Uint64, y: Uint64) -> Uint64 ``` Computes the sum of its operands. @@ -176,7 +176,7 @@ No other changes yet. ```grain -(-) : (Uint64, Uint64) -> Uint64 +(-) : (x: Uint64, y: Uint64) -> Uint64 ``` Computes the difference of its operands. @@ -202,7 +202,7 @@ No other changes yet. ```grain -(*) : (Uint64, Uint64) -> Uint64 +(*) : (x: Uint64, y: Uint64) -> Uint64 ``` Computes the product of its operands. @@ -228,7 +228,7 @@ No other changes yet. ```grain -(/) : (Uint64, Uint64) -> Uint64 +(/) : (x: Uint64, y: Uint64) -> Uint64 ``` Computes the quotient of its operands. @@ -254,7 +254,7 @@ No other changes yet. ```grain -rem : (Uint64, Uint64) -> Uint64 +rem : (x: Uint64, y: Uint64) -> Uint64 ``` Computes the remainder of the division of its operands. @@ -280,7 +280,7 @@ No other changes yet. ```grain -rotl : (Uint64, Uint64) -> Uint64 +rotl : (value: Uint64, amount: Uint64) -> Uint64 ``` Rotates the bits of the value left by the given number of bits. @@ -306,7 +306,7 @@ No other changes yet. ```grain -rotr : (Uint64, Uint64) -> Uint64 +rotr : (value: Uint64, amount: Uint64) -> Uint64 ``` Rotates the bits of the value right by the given number of bits. @@ -332,7 +332,7 @@ No other changes yet. ```grain -(<<) : (Uint64, Uint64) -> Uint64 +(<<) : (value: Uint64, amount: Uint64) -> Uint64 ``` Shifts the bits of the value left by the given number of bits. @@ -358,7 +358,7 @@ No other changes yet. ```grain -(>>>) : (Uint64, Uint64) -> Uint64 +(>>>) : (value: Uint64, amount: Uint64) -> Uint64 ``` Shifts the bits of the value right by the given number of bits. @@ -384,7 +384,7 @@ No other changes yet. ```grain -(==) : (Uint64, Uint64) -> Bool +(==) : (x: Uint64, y: Uint64) -> Bool ``` Checks if the first value is equal to the second value. @@ -410,7 +410,7 @@ No other changes yet. ```grain -(!=) : (Uint64, Uint64) -> Bool +(!=) : (x: Uint64, y: Uint64) -> Bool ``` Checks if the first value is not equal to the second value. @@ -436,7 +436,7 @@ No other changes yet. ```grain -eqz : Uint64 -> Bool +eqz : (value: Uint64) -> Bool ``` Checks if the given value is equal to zero. @@ -461,7 +461,7 @@ No other changes yet. ```grain -(<) : (Uint64, Uint64) -> Bool +(<) : (x: Uint64, y: Uint64) -> Bool ``` Checks if the first value is less than the second value. @@ -487,7 +487,7 @@ No other changes yet. ```grain -(>) : (Uint64, Uint64) -> Bool +(>) : (x: Uint64, y: Uint64) -> Bool ``` Checks if the first value is greater than the second value. @@ -513,7 +513,7 @@ No other changes yet. ```grain -(<=) : (Uint64, Uint64) -> Bool +(<=) : (x: Uint64, y: Uint64) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -539,7 +539,7 @@ No other changes yet. ```grain -(>=) : (Uint64, Uint64) -> Bool +(>=) : (x: Uint64, y: Uint64) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -565,7 +565,7 @@ No other changes yet. ```grain -lnot : Uint64 -> Uint64 +lnot : (value: Uint64) -> Uint64 ``` Computes the bitwise NOT of the given value. @@ -590,7 +590,7 @@ No other changes yet. ```grain -(&) : (Uint64, Uint64) -> Uint64 +(&) : (x: Uint64, y: Uint64) -> Uint64 ``` Computes the bitwise AND (`&`) on the given operands. @@ -616,7 +616,7 @@ No other changes yet. ```grain -(|) : (Uint64, Uint64) -> Uint64 +(|) : (x: Uint64, y: Uint64) -> Uint64 ``` Computes the bitwise OR (`|`) on the given operands. @@ -642,7 +642,7 @@ No other changes yet. ```grain -(^) : (Uint64, Uint64) -> Uint64 +(^) : (x: Uint64, y: Uint64) -> Uint64 ``` Computes the bitwise XOR (`^`) on the given operands. @@ -668,7 +668,7 @@ No other changes yet. ```grain -clz : Uint64 -> Uint64 +clz : (value: Uint64) -> Uint64 ``` Counts the number of leading zero bits in the value. @@ -693,7 +693,7 @@ No other changes yet. ```grain -ctz : Uint64 -> Uint64 +ctz : (value: Uint64) -> Uint64 ``` Counts the number of trailing zero bits in the value. @@ -718,7 +718,7 @@ No other changes yet. ```grain -popcnt : Uint64 -> Uint64 +popcnt : (value: Uint64) -> Uint64 ``` Counts the number of bits set to `1` in the value, also known as a population count. diff --git a/stdlib/uint8.md b/stdlib/uint8.md index b9759592e4..c606326192 100644 --- a/stdlib/uint8.md +++ b/stdlib/uint8.md @@ -25,7 +25,7 @@ No other changes yet. ```grain -fromNumber : Number -> Uint8 +fromNumber : (number: Number) -> Uint8 ``` Converts a Number to a Uint8. @@ -50,7 +50,7 @@ No other changes yet. ```grain -toNumber : Uint8 -> Number +toNumber : (value: Uint8) -> Number ``` Converts a Uint8 to a Number. @@ -75,7 +75,7 @@ No other changes yet. ```grain -fromInt8 : Int8 -> Uint8 +fromInt8 : (x: Int8) -> Uint8 ``` Converts an Int8 to a Uint8. @@ -100,7 +100,7 @@ No other changes yet. ```grain -incr : Uint8 -> Uint8 +incr : (value: Uint8) -> Uint8 ``` Increments the value by one. @@ -125,7 +125,7 @@ No other changes yet. ```grain -decr : Uint8 -> Uint8 +decr : (value: Uint8) -> Uint8 ``` Decrements the value by one. @@ -150,7 +150,7 @@ No other changes yet. ```grain -(+) : (Uint8, Uint8) -> Uint8 +(+) : (x: Uint8, y: Uint8) -> Uint8 ``` Computes the sum of its operands. @@ -176,7 +176,7 @@ No other changes yet. ```grain -(-) : (Uint8, Uint8) -> Uint8 +(-) : (x: Uint8, y: Uint8) -> Uint8 ``` Computes the difference of its operands. @@ -202,7 +202,7 @@ No other changes yet. ```grain -(*) : (Uint8, Uint8) -> Uint8 +(*) : (x: Uint8, y: Uint8) -> Uint8 ``` Computes the product of its operands. @@ -228,7 +228,7 @@ No other changes yet. ```grain -(/) : (Uint8, Uint8) -> Uint8 +(/) : (x: Uint8, y: Uint8) -> Uint8 ``` Computes the quotient of its operands. @@ -254,7 +254,7 @@ No other changes yet. ```grain -rem : (Uint8, Uint8) -> Uint8 +rem : (x: Uint8, y: Uint8) -> Uint8 ``` Computes the remainder of the division of its operands. @@ -280,7 +280,7 @@ No other changes yet. ```grain -(<<) : (Uint8, Uint8) -> Uint8 +(<<) : (value: Uint8, amount: Uint8) -> Uint8 ``` Shifts the bits of the value left by the given number of bits. @@ -306,7 +306,7 @@ No other changes yet. ```grain -(>>>) : (Uint8, Uint8) -> Uint8 +(>>>) : (value: Uint8, amount: Uint8) -> Uint8 ``` Shifts the bits of the value right by the given number of bits. @@ -332,7 +332,7 @@ No other changes yet. ```grain -(==) : (Uint8, Uint8) -> Bool +(==) : (x: Uint8, y: Uint8) -> Bool ``` Checks if the first value is equal to the second value. @@ -358,7 +358,7 @@ No other changes yet. ```grain -(!=) : (Uint8, Uint8) -> Bool +(!=) : (x: Uint8, y: Uint8) -> Bool ``` Checks if the first value is not equal to the second value. @@ -384,7 +384,7 @@ No other changes yet. ```grain -(<) : (Uint8, Uint8) -> Bool +(<) : (x: Uint8, y: Uint8) -> Bool ``` Checks if the first value is less than the second value. @@ -410,7 +410,7 @@ No other changes yet. ```grain -(>) : (Uint8, Uint8) -> Bool +(>) : (x: Uint8, y: Uint8) -> Bool ``` Checks if the first value is greater than the second value. @@ -436,7 +436,7 @@ No other changes yet. ```grain -(<=) : (Uint8, Uint8) -> Bool +(<=) : (x: Uint8, y: Uint8) -> Bool ``` Checks if the first value is less than or equal to the second value. @@ -462,7 +462,7 @@ No other changes yet. ```grain -(>=) : (Uint8, Uint8) -> Bool +(>=) : (x: Uint8, y: Uint8) -> Bool ``` Checks if the first value is greater than or equal to the second value. @@ -488,7 +488,7 @@ No other changes yet. ```grain -lnot : Uint8 -> Uint8 +lnot : (value: Uint8) -> Uint8 ``` Computes the bitwise NOT of the given value. @@ -513,7 +513,7 @@ No other changes yet. ```grain -(&) : (Uint8, Uint8) -> Uint8 +(&) : (x: Uint8, y: Uint8) -> Uint8 ``` Computes the bitwise AND (`&`) on the given operands. @@ -539,7 +539,7 @@ No other changes yet. ```grain -(|) : (Uint8, Uint8) -> Uint8 +(|) : (x: Uint8, y: Uint8) -> Uint8 ``` Computes the bitwise OR (`|`) on the given operands. @@ -565,7 +565,7 @@ No other changes yet. ```grain -(^) : (Uint8, Uint8) -> Uint8 +(^) : (x: Uint8, y: Uint8) -> Uint8 ``` Computes the bitwise XOR (`^`) on the given operands.