From 7fff8bfa77efc5f42b53f870576f23961b8591c9 Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Sun, 10 Jan 2021 14:30:29 +1100 Subject: [PATCH 1/5] Add uncurry decorator syntax lookup --- misc_docs/syntax/decorator_uncurry.mdx | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 misc_docs/syntax/decorator_uncurry.mdx diff --git a/misc_docs/syntax/decorator_uncurry.mdx b/misc_docs/syntax/decorator_uncurry.mdx new file mode 100644 index 000000000..d0af2424a --- /dev/null +++ b/misc_docs/syntax/decorator_uncurry.mdx @@ -0,0 +1,34 @@ +--- +id: "uncurry-decorator" +keywords: ["uncurry", "decorator"] +name: "@uncurry" +summary: "This is the `@uncurry` decorator." +category: "decorators" +--- + +The `@uncurry` decorator allows you to annotate *external* function callback arguments +so the callbacks may be declared as normal functions `() => { ... }` rather then needing +the uncurried function syntax `(.) => { ... }`. + +### Example + + + +```res +@bs.send +external map: (array<'a>, @uncurry ('a => 'b)) => array<'b> = "map" + +let result = map([1, 2, 3], x => x + 1) +``` + +```js +var result = [1, 2, 3].map(function (x) { + return (x + 1) | 0 +}) +``` + + + +### References + +- [Curry & Uncurry](/docs/manual/latest/bind-to-js-function#curry--uncurry) From 8986afe9618647278cec02eaa97b0e07ef042a91 Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Sun, 10 Jan 2021 14:37:24 +1100 Subject: [PATCH 2/5] Tweak uncurry decorator --- misc_docs/syntax/decorator_uncurry.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc_docs/syntax/decorator_uncurry.mdx b/misc_docs/syntax/decorator_uncurry.mdx index d0af2424a..1c2146621 100644 --- a/misc_docs/syntax/decorator_uncurry.mdx +++ b/misc_docs/syntax/decorator_uncurry.mdx @@ -6,8 +6,8 @@ summary: "This is the `@uncurry` decorator." category: "decorators" --- -The `@uncurry` decorator allows you to annotate *external* function callback arguments -so the callbacks may be declared as normal functions `() => { ... }` rather then needing +The `@uncurry` decorator allows you to annotate **external** function callback argument types +so when writing the callbacks they may be declared as normal functions `() => { ... }` rather then needing the uncurried function syntax `(.) => { ... }`. ### Example From 3d0a569335c749aa892afb4d818482a8f82bf1c1 Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Sun, 10 Jan 2021 14:50:11 +1100 Subject: [PATCH 3/5] Fix uncurried decorator typo --- misc_docs/syntax/decorator_uncurry.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc_docs/syntax/decorator_uncurry.mdx b/misc_docs/syntax/decorator_uncurry.mdx index 1c2146621..a4377bf2f 100644 --- a/misc_docs/syntax/decorator_uncurry.mdx +++ b/misc_docs/syntax/decorator_uncurry.mdx @@ -7,8 +7,8 @@ category: "decorators" --- The `@uncurry` decorator allows you to annotate **external** function callback argument types -so when writing the callbacks they may be declared as normal functions `() => { ... }` rather then needing -the uncurried function syntax `(.) => { ... }`. +so when writing the callbacks they may be declared as normal functions `() => { ... }` +rather than needing the uncurried function syntax `(.) => { ... }`. ### Example From 6484f6084504e885589fdcd88cd0659a00bfdca1 Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Sun, 10 Jan 2021 21:53:57 +1100 Subject: [PATCH 4/5] Update uncurry decorator reference --- misc_docs/syntax/decorator_uncurry.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc_docs/syntax/decorator_uncurry.mdx b/misc_docs/syntax/decorator_uncurry.mdx index a4377bf2f..25cc99f45 100644 --- a/misc_docs/syntax/decorator_uncurry.mdx +++ b/misc_docs/syntax/decorator_uncurry.mdx @@ -31,4 +31,4 @@ var result = [1, 2, 3].map(function (x) { ### References -- [Curry & Uncurry](/docs/manual/latest/bind-to-js-function#curry--uncurry) +- [Use Guaranteed Uncurrying](/docs/manual/latest/bind-to-js-function#solution-use-guaranteed-uncurrying) From 416ecff3c5bf00e1d798cdd8a07574ec4f2aab37 Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Fri, 15 Jan 2021 20:42:41 +1100 Subject: [PATCH 5/5] Update with PR suggestions --- misc_docs/syntax/decorator_uncurry.mdx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/misc_docs/syntax/decorator_uncurry.mdx b/misc_docs/syntax/decorator_uncurry.mdx index 25cc99f45..9436bf327 100644 --- a/misc_docs/syntax/decorator_uncurry.mdx +++ b/misc_docs/syntax/decorator_uncurry.mdx @@ -6,12 +6,12 @@ summary: "This is the `@uncurry` decorator." category: "decorators" --- -The `@uncurry` decorator allows you to annotate **external** function callback argument types -so when writing the callbacks they may be declared as normal functions `() => { ... }` -rather than needing the uncurried function syntax `(.) => { ... }`. +The `@uncurry` decorator can be used to mark any callback argument within an **external** function as an uncurried function without the need for any [explicit uncurried function syntax](/docs/manual/latest/function#uncurried-function) `((.) => { ... })`. ### Example +In the following example we are binding to a function `map(arr, callback)` and use the `@uncurry` annotation to make sure that `callback` is always treated as an uncurried function: + ```res @@ -29,6 +29,8 @@ var result = [1, 2, 3].map(function (x) { +As we can see, we defined a regular function `('a) => 'b` instead of `(. 'a) => 'b`, but still have all the guarantees. Please note that the compiler does a lot of optimizations, so the example above will compile to the same code even without the `@uncurry` decorator. Adding the decorator (or using the `(.) =>` syntax) makes the output 100% predictable though. + ### References - [Use Guaranteed Uncurrying](/docs/manual/latest/bind-to-js-function#solution-use-guaranteed-uncurrying)