From 18b46b89c3d629f5d6850726a1cca6a3733707f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Tsnobiladz=C3=A9?= Date: Wed, 12 Feb 2025 22:29:22 +0100 Subject: [PATCH 1/4] add a type t as an alias of the built-in type --- runtime/Stdlib_Array.res | 1 + runtime/Stdlib_Array.resi | 10 ++++++++++ runtime/Stdlib_BigInt.res | 5 +++++ runtime/Stdlib_Float.res | 2 ++ runtime/Stdlib_Float.resi | 5 +++++ runtime/Stdlib_Int.res | 2 ++ runtime/Stdlib_Int.resi | 5 +++++ runtime/Stdlib_List.res | 2 ++ runtime/Stdlib_List.resi | 5 +++++ runtime/Stdlib_Option.res | 1 + runtime/Stdlib_Option.resi | 5 +++++ runtime/Stdlib_Result.res | 1 + runtime/Stdlib_Result.resi | 2 ++ runtime/Stdlib_String.res | 2 ++ runtime/Stdlib_String.resi | 5 +++++ 15 files changed, 53 insertions(+) diff --git a/runtime/Stdlib_Array.res b/runtime/Stdlib_Array.res index 4296a92516..011d1cf564 100644 --- a/runtime/Stdlib_Array.res +++ b/runtime/Stdlib_Array.res @@ -1,3 +1,4 @@ +type t<'a> = array<'a> type arrayLike<'a> @new external makeUninitializedUnsafe: int => array<'a> = "Array" diff --git a/runtime/Stdlib_Array.resi b/runtime/Stdlib_Array.resi index a5fc024669..e2bb72b1e6 100644 --- a/runtime/Stdlib_Array.resi +++ b/runtime/Stdlib_Array.resi @@ -1,3 +1,13 @@ +/*** +A mutable array. + +Compiles to a regular JavaScript array.*/ + +/** +Type representing an array of value `'a`. +*/ +type t<'a> = array<'a> + type arrayLike<'a> /** diff --git a/runtime/Stdlib_BigInt.res b/runtime/Stdlib_BigInt.res index b39efdae0d..ddceef99b3 100644 --- a/runtime/Stdlib_BigInt.res +++ b/runtime/Stdlib_BigInt.res @@ -1,3 +1,8 @@ +/** +Type representing a bigint. +*/ +type t = bigint + @val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN" @val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN" diff --git a/runtime/Stdlib_Float.res b/runtime/Stdlib_Float.res index 13189644b5..ab1504c7bb 100644 --- a/runtime/Stdlib_Float.res +++ b/runtime/Stdlib_Float.res @@ -1,3 +1,5 @@ +type t = float + module Constants = { @val external nan: float = "NaN" @val external epsilon: float = "Number.EPSILON" diff --git a/runtime/Stdlib_Float.resi b/runtime/Stdlib_Float.resi index 2241a08aff..f6943cc3d1 100644 --- a/runtime/Stdlib_Float.resi +++ b/runtime/Stdlib_Float.resi @@ -26,6 +26,11 @@ Functions for interacting with float. */ +/** +Type representing a float. +*/ +type t = float + /** Float constants. */ diff --git a/runtime/Stdlib_Int.res b/runtime/Stdlib_Int.res index ffee8b8742..569c038f44 100644 --- a/runtime/Stdlib_Int.res +++ b/runtime/Stdlib_Int.res @@ -1,3 +1,5 @@ +type t = int + module Constants = { @inline let minValue = -2147483648 @inline let maxValue = 2147483647 diff --git a/runtime/Stdlib_Int.resi b/runtime/Stdlib_Int.resi index 9d4b5f1849..a853179a9e 100644 --- a/runtime/Stdlib_Int.resi +++ b/runtime/Stdlib_Int.resi @@ -27,6 +27,11 @@ Functions for interacting with JavaScript Number. See: [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number). */ +/** +Type representing an int. +*/ +type t = int + module Constants: { /** The smallest positive number represented in JavaScript. diff --git a/runtime/Stdlib_List.res b/runtime/Stdlib_List.res index 0e2bef4bc8..a4004f4b6e 100644 --- a/runtime/Stdlib_List.res +++ b/runtime/Stdlib_List.res @@ -61,6 +61,8 @@ @@config({flags: ["-bs-noassertfalse"]}) +type t<'a> = list<'a> + module A = { @new external makeUninitializedUnsafe: int => array<'a> = "Array" external min: ('a, 'a) => 'a = "%bs_min" diff --git a/runtime/Stdlib_List.resi b/runtime/Stdlib_List.resi index 8759f87d8f..8643c9f0eb 100644 --- a/runtime/Stdlib_List.resi +++ b/runtime/Stdlib_List.resi @@ -31,6 +31,11 @@ Collection functions for manipulating the `list` data structures, a singly-linke - Better interop with JavaScript - Better memory usage & performance. */ +/** +Type representing a list of value `'a`. +*/ +type t<'a> = list<'a> + /** `length(list)` returns the length of `list`. diff --git a/runtime/Stdlib_Option.res b/runtime/Stdlib_Option.res index c8d84d3574..da8854a9fd 100644 --- a/runtime/Stdlib_Option.res +++ b/runtime/Stdlib_Option.res @@ -21,6 +21,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +type t<'a> = option<'a> = None | Some('a) let filter = (opt, p) => switch opt { diff --git a/runtime/Stdlib_Option.resi b/runtime/Stdlib_Option.resi index e205983cff..a105381bd3 100644 --- a/runtime/Stdlib_Option.resi +++ b/runtime/Stdlib_Option.resi @@ -39,6 +39,11 @@ let someString: option = Some("hello") ``` */ +/** +Type representing an option of type 'a. +*/ +type t<'a> = option<'a> = None | Some('a) + /** `filter(opt, f)` applies `f` to `opt`, if `f` returns `true`, then it returns `Some(value)`, otherwise returns `None`. diff --git a/runtime/Stdlib_Result.res b/runtime/Stdlib_Result.res index 8f0ce15186..0c37cfabad 100644 --- a/runtime/Stdlib_Result.res +++ b/runtime/Stdlib_Result.res @@ -21,6 +21,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err) let getExn = x => switch x { diff --git a/runtime/Stdlib_Result.resi b/runtime/Stdlib_Result.resi index 5217a7ef9d..2debed4a61 100644 --- a/runtime/Stdlib_Result.resi +++ b/runtime/Stdlib_Result.resi @@ -45,6 +45,8 @@ } ``` */ +type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err) + /** `getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception diff --git a/runtime/Stdlib_String.res b/runtime/Stdlib_String.res index 18f8de1267..3d25372be1 100644 --- a/runtime/Stdlib_String.res +++ b/runtime/Stdlib_String.res @@ -1,3 +1,5 @@ +type t = string + @val external make: 'a => string = "String" @val external fromCharCode: int => string = "String.fromCharCode" diff --git a/runtime/Stdlib_String.resi b/runtime/Stdlib_String.resi index e769529662..3ce6614296 100644 --- a/runtime/Stdlib_String.resi +++ b/runtime/Stdlib_String.resi @@ -27,6 +27,11 @@ Functions for interacting with JavaScript strings. See: [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String). */ +/** +Type representing a string. +*/ +type t = string + /** `make(value)` converts the given value to a `string`. From c8b2dc2b022a22b12f4c1da3095f82ddf92a452d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Tsnobiladz=C3=A9?= Date: Thu, 13 Feb 2025 10:18:47 +0100 Subject: [PATCH 2/4] fix docstring test --- runtime/Stdlib_Result.resi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/Stdlib_Result.resi b/runtime/Stdlib_Result.resi index 2debed4a61..22de5918b7 100644 --- a/runtime/Stdlib_Result.resi +++ b/runtime/Stdlib_Result.resi @@ -53,7 +53,10 @@ type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err) ```res example Result.getExn(Result.Ok(42)) == 42 - Result.getExn(Result.Error("Invalid data")) /* raises exception */ + switch Result.getExn(Error("Invalid data")) { + | exception Not_found => assert(true) + | _ => assert(false) + } ``` */ let getExn: result<'a, 'b> => 'a From f9a40c47bfcec3dbdea834ce0b579aa0611ffa29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Tsnobiladz=C3=A9?= Date: Mon, 17 Feb 2025 16:39:13 +0100 Subject: [PATCH 3/4] fix completion tests --- tests/analysis_tests/tests/src/expected/Completion.res.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/analysis_tests/tests/src/expected/Completion.res.txt b/tests/analysis_tests/tests/src/expected/Completion.res.txt index acfedc580a..ea276bdb69 100644 --- a/tests/analysis_tests/tests/src/expected/Completion.res.txt +++ b/tests/analysis_tests/tests/src/expected/Completion.res.txt @@ -1951,7 +1951,7 @@ Path this "kind": 12, "tags": [], "detail": "\\\"Type Not Known\"", - "documentation": {"kind": "markdown", "value": "```rescript\ntype props<'first, 'zoo, 'second> = {\n first?: 'first,\n zoo?: 'zoo,\n second: 'second,\n}\n```"} + "documentation": null }] Hover src/Completion.res 349:14 @@ -2511,7 +2511,7 @@ Path Stdlib.Result.g "kind": 12, "tags": [], "detail": "result<'a, 'b> => 'a", - "documentation": {"kind": "markdown", "value": "\n Result types are really useful to describe the result of a certain operation\n without relying on exceptions or `option` types.\n\n This module gives you useful utilities to create and combine `Result` data.\n"} + "documentation": {"kind": "markdown", "value": "\n `getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception\n\n ```res example\n Result.getExn(Result.Ok(42)) == 42\n\n switch Result.getExn(Error(\"Invalid data\")) {\n | exception Not_found => assert(true)\n | _ => assert(false)\n }\n ```\n"} }, { "label": "Result.getOr", "kind": 12, From d60092b7ce95cd0d83388fb87f70b23d60b82305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Tsnobiladz=C3=A9?= Date: Mon, 17 Feb 2025 16:40:22 +0100 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6980a3f82d..0121020281 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Allow single newline in JSX. https://github.com/rescript-lang/rescript/pull/7269 - Editor: Always complete from Core first. Use actual native regex syntax in code snippets for regexps. https://github.com/rescript-lang/rescript/pull/7295 +- Add `type t` to Stdlib modules. https://github.com/rescript-lang/rescript/pull/7302 #### :bug: Bug fix