Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Syntax lookup: function / uncurried function #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions misc_docs/syntax/function_uncurried.mdx

This file was deleted.

31 changes: 31 additions & 0 deletions misc_docs/syntax/language_function.mdx
Original file line number Diff line number Diff line change
@@ -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

<CodeTab labels={["ReScript", "JS Output"]}>

```res
let greet = (name: string) => {
"Hello " ++ name
}
```

```js
function greet(name) {
return "Hello " + name;
}
```

</CodeTab>

### References

* [Function](/docs/manual/latest/function)
41 changes: 41 additions & 0 deletions misc_docs/syntax/language_uncurried_function.mdx
Original file line number Diff line number Diff line change
@@ -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 argument list.

### Example

<CodeTab labels={["ReScript", "JS Output"]}>

```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);
}
```

</CodeTab>

### References

- [Uncurried Function](/docs/manual/latest/function#uncurried-function)