Skip to content

Commit

Permalink
Add type t to Stdlib modules (#7302)
Browse files Browse the repository at this point in the history
* add a type t as an alias of the built-in types
  • Loading branch information
tsnobip authored Feb 17, 2025
1 parent d1c9aef commit 5b7e803
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Array.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type t<'a> = array<'a>
type arrayLike<'a>

@new external makeUninitializedUnsafe: int => array<'a> = "Array"
Expand Down
10 changes: 10 additions & 0 deletions runtime/Stdlib_Array.resi
Original file line number Diff line number Diff line change
@@ -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>

/**
Expand Down
5 changes: 5 additions & 0 deletions runtime/Stdlib_BigInt.res
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 2 additions & 0 deletions runtime/Stdlib_Float.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type t = float

module Constants = {
@val external nan: float = "NaN"
@val external epsilon: float = "Number.EPSILON"
Expand Down
5 changes: 5 additions & 0 deletions runtime/Stdlib_Float.resi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
Functions for interacting with float.
*/

/**
Type representing a float.
*/
type t = float

/**
Float constants.
*/
Expand Down
2 changes: 2 additions & 0 deletions runtime/Stdlib_Int.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type t = int

module Constants = {
@inline let minValue = -2147483648
@inline let maxValue = 2147483647
Expand Down
5 changes: 5 additions & 0 deletions runtime/Stdlib_Int.resi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions runtime/Stdlib_List.res
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions runtime/Stdlib_List.resi
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Option.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions runtime/Stdlib_Option.resi
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ let someString: option<string> = 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`.
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Result.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion runtime/Stdlib_Result.resi
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@
}
```
*/
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
```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
Expand Down
2 changes: 2 additions & 0 deletions runtime/Stdlib_String.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type t = string

@val external make: 'a => string = "String"

@val external fromCharCode: int => string = "String.fromCharCode"
Expand Down
5 changes: 5 additions & 0 deletions runtime/Stdlib_String.resi
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis_tests/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5b7e803

Please sign in to comment.