From 5047073fc0834d25cda5a66bdb266e6e1c37998f Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Mon, 3 May 2021 19:51:11 +1000 Subject: [PATCH 1/3] Syntax Lookup: Open --- misc_docs/syntax/language_open.mdx | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 misc_docs/syntax/language_open.mdx diff --git a/misc_docs/syntax/language_open.mdx b/misc_docs/syntax/language_open.mdx new file mode 100644 index 000000000..996927eee --- /dev/null +++ b/misc_docs/syntax/language_open.mdx @@ -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. + +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. + +### Example + + + +```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); +} +``` + + + +### 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) From 413935af31dbed8541239a4b2c2d996293f31820 Mon Sep 17 00:00:00 2001 From: Patrick Ecker Date: Wed, 5 May 2021 19:16:40 +0200 Subject: [PATCH 2/3] Update misc_docs/syntax/language_open.mdx --- misc_docs/syntax/language_open.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc_docs/syntax/language_open.mdx b/misc_docs/syntax/language_open.mdx index 996927eee..f2311af3d 100644 --- a/misc_docs/syntax/language_open.mdx +++ b/misc_docs/syntax/language_open.mdx @@ -8,7 +8,7 @@ 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. -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. +In some cases, `open` will cause a "shadow warning" due to existing identifiers and types being redefined by an `open`ed module. You can explicitly ignore that warning by using an `open!` statement instead. ### Example From be98ae6b4554d29a8d520a80c7e4bdf6aaa1cdff Mon Sep 17 00:00:00 2001 From: Patrick Ecker Date: Wed, 5 May 2021 19:16:45 +0200 Subject: [PATCH 3/3] Update misc_docs/syntax/language_open.mdx --- misc_docs/syntax/language_open.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc_docs/syntax/language_open.mdx b/misc_docs/syntax/language_open.mdx index f2311af3d..0e52bc1b1 100644 --- a/misc_docs/syntax/language_open.mdx +++ b/misc_docs/syntax/language_open.mdx @@ -6,7 +6,7 @@ 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. +`open` is used to expose all values, types, modules, etc of a module in the current scope. This is useful whenever you want to use a module's functionality without typing out the module name over and over again. In some cases, `open` will cause a "shadow warning" due to existing identifiers and types being redefined by an `open`ed module. You can explicitly ignore that warning by using an `open!` statement instead.