From d0e6597dc2daf8e7b47f7bd20256433dffb96acc Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Mon, 8 Mar 2021 19:02:48 +1100 Subject: [PATCH 1/2] Syntac lookup: function / uncurried function --- misc_docs/syntax/function_uncurried.mdx | 11 ----- misc_docs/syntax/language_function.mdx | 31 ++++++++++++++ .../syntax/language_uncurried_function.mdx | 41 +++++++++++++++++++ 3 files changed, 72 insertions(+), 11 deletions(-) delete mode 100644 misc_docs/syntax/function_uncurried.mdx create mode 100644 misc_docs/syntax/language_function.mdx create mode 100644 misc_docs/syntax/language_uncurried_function.mdx diff --git a/misc_docs/syntax/function_uncurried.mdx b/misc_docs/syntax/function_uncurried.mdx deleted file mode 100644 index d6d0e1503..000000000 --- a/misc_docs/syntax/function_uncurried.mdx +++ /dev/null @@ -1,11 +0,0 @@ ---- -test: "foo" ---- - -The `(.) => { ... }` (uncurried) syntax defines a function type that is not curried by default. This is useful whenever you want to make sure that your function is not being curried unintentionally, or if you want to force the compiler to emit cleaner JS source code (JS doesn't have curried functions by default). - -```res -let myFn = (cb: (. int) => unit) => { - cb(. 1) -} -``` diff --git a/misc_docs/syntax/language_function.mdx b/misc_docs/syntax/language_function.mdx new file mode 100644 index 000000000..5d24918d7 --- /dev/null +++ b/misc_docs/syntax/language_function.mdx @@ -0,0 +1,31 @@ +--- +id: "function" +keywords: ["function"] +name: "() => {}" +summary: "This is a `function`." +category: "languageconstructs" +--- + +Functions are declared with arguments in parentheses, an arrow, and a return expression. + +### Example + + + +```res +let greet = (name: string) => { + "Hello " ++ name +} +``` + +```js +function greet(name) { + return "Hello " + name; +} +``` + + + +### References + +* [Function](/docs/manual/latest/function) diff --git a/misc_docs/syntax/language_uncurried_function.mdx b/misc_docs/syntax/language_uncurried_function.mdx new file mode 100644 index 000000000..908ac7aba --- /dev/null +++ b/misc_docs/syntax/language_uncurried_function.mdx @@ -0,0 +1,41 @@ +--- +id: "uncurried-function" +keywords: ["function", "uncurried"] +name: "(.) => {}" +summary: "This is an `uncurried function`." +category: "languageconstructs" +--- + +ReScript functions are curried by default, however in certain cases you may need an uncurried function. In these cases we add a `.` in the argument list. + +When calling uncurried functions, we must also include a `.` in the agument list. + +### Example + + + +```res +let add = (. x, y) => { + x + y +} + +let withCallback = (cb: (. int) => unit) => { + cb(. 1) +} +``` + +```js +function add(x, y) { + return (x + y) | 0; +} + +function withCallback(cb) { + return cb(1); +} +``` + + + +### References + +- [Uncurried Function](/docs/manual/latest/function#uncurried-function) From 9f09441b691d138121df14e8f546aebd5fa1c45b Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Mon, 8 Mar 2021 19:05:06 +1100 Subject: [PATCH 2/2] Fix typo --- misc_docs/syntax/language_uncurried_function.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc_docs/syntax/language_uncurried_function.mdx b/misc_docs/syntax/language_uncurried_function.mdx index 908ac7aba..d1e7a44f7 100644 --- a/misc_docs/syntax/language_uncurried_function.mdx +++ b/misc_docs/syntax/language_uncurried_function.mdx @@ -8,7 +8,7 @@ category: "languageconstructs" ReScript functions are curried by default, however in certain cases you may need an uncurried function. In these cases we add a `.` in the argument list. -When calling uncurried functions, we must also include a `.` in the agument list. +When calling uncurried functions, we must also include a `.` in the argument list. ### Example