Skip to content
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

Syntax lookup: Open #315

Merged
merged 3 commits into from
May 5, 2021
Merged
Changes from 1 commit
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
35 changes: 35 additions & 0 deletions misc_docs/syntax/language_open.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: "open"
keywords: ["open", "module"]
name: "open"
summary: "This is the `open` keyword."
category: "languageconstructs"
---

`open` is used to "open" a module so we can refer to the module's contents without needing to prepending the module's name.
ryyppy marked this conversation as resolved.
Show resolved Hide resolved

In some cases, `open` will cause a warning due to existing identifiers and types being redefined by the opened module. In these cases, we can use `open!` instead which will suppress the warnings.
ryyppy marked this conversation as resolved.
Show resolved Hide resolved

### Example

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

```res
open Js.Math

// Use _PI and pow_float from the Js.Math module
let area = radius => _PI *. pow_float(~base=radius, ~exp=2.0)
```

```js
function area(radius) {
return Math.PI * Math.pow(radius, 2.0);
}
```

</CodeTab>

### References

* [Opening a module](/docs/manual/latest/module#opening-a-module)
* [Use open! to ignore shadow warnings](/docs/manual/latest/module#use-open-to-ignore-shadow-warnings)