Skip to content

Commit 42038a5

Browse files
committed
Stdlib namespace for Core modules
1 parent 4cd02f9 commit 42038a5

File tree

83 files changed

+316
-773
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+316
-773
lines changed

compiler/core/res_compmisc.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ let initial_env ?modulename () =
5454
let initial = Env.initial_safe_string in
5555
let env =
5656
if !Clflags.nopervasives then initial
57-
else open_implicit_module "Pervasives" initial
57+
else
58+
initial
59+
|> open_implicit_module "Pervasives"
60+
|> open_implicit_module "Stdlib"
5861
in
5962
List.fold_left
6063
(fun env m -> open_implicit_module m env)

compiler/gentype/TranslateTypeExprFromTypes.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
8686
{dependencies = []; type_ = string_t}
8787
| (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"]), [] ->
8888
{dependencies = []; type_ = bigint_t}
89-
| (["Js"; "Date"; "t"] | ["Date"; "t"]), [] ->
89+
| (["Js"; "Date"; "t"] | ["Date"; "t"] | ["Stdlib_Date"; "t"]), [] ->
9090
{dependencies = []; type_ = date_t}
9191
| ["Map"; "t"], [param_translation1; param_translation2] ->
9292
{
@@ -110,7 +110,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
110110
dependencies = param_translation.dependencies;
111111
type_ = weakset_t param_translation.type_;
112112
}
113-
| (["Js"; "Re"; "t"] | ["RegExp"; "t"]), [] ->
113+
| (["Js"; "Re"; "t"] | ["Stdlib_RegExp"; "t"]), [] ->
114114
{dependencies = []; type_ = regexp_t}
115115
| (["FB"; "unit"] | ["unit"]), [] -> {dependencies = []; type_ = unit_t}
116116
| ( (["FB"; "array"] | ["array"] | ["Js"; ("Array" | "Array2"); "t"]),

compiler/ml/ast_untagged_variants.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) =
179179
| Tconstr (path, _, _) when Path.same path Predef.path_array -> Some Array
180180
| Tconstr (path, _, _) -> (
181181
match Path.name path with
182-
| "Js_date.t" -> Some Date
183-
| "Js_re.t" -> Some RegExp
182+
| "Stdlib_Date.t" -> Some Date
183+
| "Stdlib_RegExp.t" -> Some RegExp
184184
| "Js_file.t" -> Some File
185185
| "Js_blob.t" -> Some Blob
186186
| _ -> None)

lib/es6/Int.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
import * as $$Array from "./Array.js";
3+
import * as Stdlib_Array from "./Stdlib_Array.js";
44

55
function fromString(x, radix) {
66
let maybeInt = radix !== undefined ? parseInt(x, radix) : parseInt(x);
@@ -46,7 +46,7 @@ function range(start, end, optionsOpt) {
4646
let range$2 = options.inclusive === true ? range$1 + 1 | 0 : range$1;
4747
length = Math.ceil(range$2 / abs(step)) | 0;
4848
}
49-
return $$Array.fromInitializer(length, i => start + Math.imul(i, step) | 0);
49+
return Stdlib_Array.fromInitializer(length, i => start + Math.imul(i, step) | 0);
5050
}
5151

5252
function rangeWithOptions(start, end, options) {

lib/es6/List.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
import * as $$Array from "./Array.js";
3+
import * as Stdlib_Array from "./Stdlib_Array.js";
44
import * as Primitive_int from "./Primitive_int.js";
55
import * as Primitive_option from "./Primitive_option.js";
66

@@ -648,7 +648,7 @@ function toArray(x) {
648648

649649
function toShuffled(xs) {
650650
let v = toArray(xs);
651-
$$Array.shuffle(v);
651+
Stdlib_Array.shuffle(v);
652652
return fromArray(v);
653653
}
654654

lib/es6/Stdlib.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
4+
let $$Array;
5+
6+
let $$Date;
7+
8+
let Dict;
9+
10+
let $$Promise;
11+
12+
let $$RegExp;
13+
14+
let Result;
15+
16+
let $$Set;
17+
18+
let $$String;
19+
20+
let $$Symbol;
21+
22+
export {
23+
$$Array,
24+
$$Date,
25+
Dict,
26+
$$Promise,
27+
$$RegExp,
28+
Result,
29+
$$Set,
30+
$$String,
31+
$$Symbol,
32+
}
33+
/* No side effect */
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/js/Int.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
let $$Array = require("./Array.js");
3+
let Stdlib_Array = require("./Stdlib_Array.js");
44

55
function fromString(x, radix) {
66
let maybeInt = radix !== undefined ? parseInt(x, radix) : parseInt(x);
@@ -46,7 +46,7 @@ function range(start, end, optionsOpt) {
4646
let range$2 = options.inclusive === true ? range$1 + 1 | 0 : range$1;
4747
length = Math.ceil(range$2 / abs(step)) | 0;
4848
}
49-
return $$Array.fromInitializer(length, i => start + Math.imul(i, step) | 0);
49+
return Stdlib_Array.fromInitializer(length, i => start + Math.imul(i, step) | 0);
5050
}
5151

5252
function rangeWithOptions(start, end, options) {

lib/js/List.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
let $$Array = require("./Array.js");
3+
let Stdlib_Array = require("./Stdlib_Array.js");
44
let Primitive_int = require("./Primitive_int.js");
55
let Primitive_option = require("./Primitive_option.js");
66

@@ -648,7 +648,7 @@ function toArray(x) {
648648

649649
function toShuffled(xs) {
650650
let v = toArray(xs);
651-
$$Array.shuffle(v);
651+
Stdlib_Array.shuffle(v);
652652
return fromArray(v);
653653
}
654654

lib/js/Stdlib.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
4+
let $$Array;
5+
6+
let $$Date;
7+
8+
let Dict;
9+
10+
let $$Promise;
11+
12+
let $$RegExp;
13+
14+
let Result;
15+
16+
let $$Set;
17+
18+
let $$String;
19+
20+
let $$Symbol;
21+
22+
exports.$$Array = $$Array;
23+
exports.$$Date = $$Date;
24+
exports.Dict = Dict;
25+
exports.$$Promise = $$Promise;
26+
exports.$$RegExp = $$RegExp;
27+
exports.Result = Result;
28+
exports.$$Set = $$Set;
29+
exports.$$String = $$String;
30+
exports.$$Symbol = $$Symbol;
31+
/* No side effect */
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

runtime/Int.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ let range = (start, end, ~options: rangeOptions={}) => {
7575
ceil(Float.fromInt(range) /. Float.fromInt(abs(step)))->Float.toInt
7676
}
7777

78-
Array.fromInitializer(~length, i => start + i * step)
78+
Stdlib_Array.fromInitializer(~length, i => start + i * step)
7979
}
8080

8181
@deprecated("Use `range` instead") @send

runtime/Intl_DateTimeFormat.res

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,17 @@ external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?
113113

114114
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
115115

116-
@send external format: (t, Date.t) => string = "format"
116+
@send external format: (t, Stdlib_Date.t) => string = "format"
117117
@send
118-
external formatToParts: (t, Date.t) => array<dateTimePart> = "formatToParts"
118+
external formatToParts: (t, Stdlib_Date.t) => array<dateTimePart> = "formatToParts"
119119

120120
@send
121-
external formatRange: (t, ~startDate: Date.t, ~endDate: Date.t) => string = "formatRange"
121+
external formatRange: (t, ~startDate: Stdlib_Date.t, ~endDate: Stdlib_Date.t) => string =
122+
"formatRange"
122123

123124
@send
124-
external formatRangeToParts: (t, ~startDate: Date.t, ~endDate: Date.t) => array<dateTimeRangePart> =
125-
"formatRangeToParts"
125+
external formatRangeToParts: (
126+
t,
127+
~startDate: Stdlib_Date.t,
128+
~endDate: Stdlib_Date.t,
129+
) => array<dateTimeRangePart> = "formatRangeToParts"

runtime/JSON.res

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ module Decode = {
8585
let string = (json: t) => Type.typeof(json) === #string ? Some((Obj.magic(json): string)) : None
8686
let float = (json: t) => Type.typeof(json) === #number ? Some((Obj.magic(json): float)) : None
8787
let object = (json: t) =>
88-
if Type.typeof(json) === #object && !Array.isArray(json) && !(Obj.magic(json) === Null.null) {
88+
if (
89+
Type.typeof(json) === #object &&
90+
!Stdlib_Array.isArray(json) &&
91+
!(Obj.magic(json) === Null.null)
92+
) {
8993
Some((Obj.magic(json): dict<t>))
9094
} else {
9195
None
9296
}
93-
let array = (json: t) => Array.isArray(json) ? Some((Obj.magic(json): array<t>)) : None
97+
let array = (json: t) => Stdlib_Array.isArray(json) ? Some((Obj.magic(json): array<t>)) : None
9498
}

runtime/Js_date.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ on MDN.) JavaScript stores dates as the number of milliseconds since the UNIX
2929
*epoch*, midnight 1 January 1970, UTC.
3030
*/
3131

32-
type t
32+
type t = Stdlib_Date.t
3333

3434
@send
3535
/**

runtime/Js_re.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ and subsequent uses will continue the search from the previous [`lastIndex`]().
3131
*/
3232

3333
/** The RegExp object. */
34-
type t
34+
type t = Stdlib_RegExp.t
3535

3636
/** The result of a executing a RegExp on a string. */
3737
type result

runtime/Js_set.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/*** ES6 Set API */
22

3-
type t<'a>
3+
type t<'a> = Stdlib_Set.t<'a>

runtime/Js_types.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

2525
/** Js symbol type only available in ES6 */
26-
type symbol
26+
type symbol = Stdlib_Symbol.t
2727

2828
type obj_val
2929
/** This type has only one value `undefined` */

runtime/Js_types.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/*** Provide utilities for manipulating JS types. */
2626

2727
/** Js symbol type (only available in ES6) */
28-
type symbol
28+
type symbol = Stdlib_Symbol.t
2929

3030
type obj_val
3131

runtime/JsxDOM.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ type domProps = {
209209
loop?: bool,
210210
low?: int,
211211
manifest?: string /* uri */,
212-
max?: string /* should be int or Js.Date.t */,
212+
max?: string /* should be int or Date.t */,
213213
maxLength?: int,
214214
media?: string /* a valid media query */,
215215
mediaGroup?: string,

runtime/List.res

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ module A = {
6969

7070
let reduceReverseU = (a, x, f) => {
7171
let r = ref(x)
72-
for i in Array.length(a) - 1 downto 0 {
73-
r.contents = f(r.contents, Array.getUnsafe(a, i))
72+
for i in Stdlib_Array.length(a) - 1 downto 0 {
73+
r.contents = f(r.contents, Stdlib_Array.getUnsafe(a, i))
7474
}
7575
r.contents
7676
}
7777

7878
let reduceReverse2U = (a, b, x, f) => {
7979
let r = ref(x)
80-
let len = min(Array.length(a), Array.length(b))
80+
let len = min(Stdlib_Array.length(a), Stdlib_Array.length(b))
8181
for i in len - 1 downto 0 {
82-
r.contents = f(r.contents, Array.getUnsafe(a, i), Array.getUnsafe(b, i))
82+
r.contents = f(r.contents, Stdlib_Array.getUnsafe(a, i), Stdlib_Array.getUnsafe(b, i))
8383
}
8484
r.contents
8585
}
@@ -467,18 +467,18 @@ let rec fillAux = (arr, i, x) =>
467467
switch x {
468468
| list{} => ()
469469
| list{h, ...t} =>
470-
Array.setUnsafe(arr, i, h)
470+
Stdlib_Array.setUnsafe(arr, i, h)
471471
fillAux(arr, i + 1, t)
472472
}
473473

474474
let rec fromArrayAux = (a, i, res) =>
475475
if i < 0 {
476476
res
477477
} else {
478-
fromArrayAux(a, i - 1, list{Array.getUnsafe(a, i), ...res})
478+
fromArrayAux(a, i - 1, list{Stdlib_Array.getUnsafe(a, i), ...res})
479479
}
480480

481-
let fromArray = a => fromArrayAux(a, Array.length(a) - 1, list{})
481+
let fromArray = a => fromArrayAux(a, Stdlib_Array.length(a) - 1, list{})
482482

483483
let toArray = (x: t<_>) => {
484484
let len = length(x)
@@ -489,7 +489,7 @@ let toArray = (x: t<_>) => {
489489

490490
let toShuffled = xs => {
491491
let v = toArray(xs)
492-
Array.shuffle(v)
492+
Stdlib_Array.shuffle(v)
493493
fromArray(v)
494494
}
495495

@@ -542,10 +542,10 @@ let concatMany = xs =>
542542
| [] => list{}
543543
| [x] => x
544544
| _ =>
545-
let len = Array.length(xs)
546-
let v = ref(Array.getUnsafe(xs, len - 1))
545+
let len = Stdlib_Array.length(xs)
546+
let v = ref(Stdlib_Array.getUnsafe(xs, len - 1))
547547
for i in len - 2 downto 0 {
548-
v.contents = concat(Array.getUnsafe(xs, i), v.contents)
548+
v.contents = concat(Stdlib_Array.getUnsafe(xs, i), v.contents)
549549
}
550550
v.contents
551551
}
@@ -761,7 +761,7 @@ let setAssoc = (xs, x, k, eq) =>
761761

762762
let sort = (xs, cmp) => {
763763
let arr = toArray(xs)
764-
Array.sort(arr, cmp)
764+
Stdlib_Array.sort(arr, cmp)
765765
fromArray(arr)
766766
}
767767

runtime/Object.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ x->Object.getSymbol(fruit) // Some("banana")
123123
```
124124
*/
125125
@get_index
126-
external getSymbol: ({..}, Symbol.t) => option<'a> = ""
126+
external getSymbol: ({..}, Stdlib_Symbol.t) => option<'a> = ""
127127

128-
@get_index external getSymbolUnsafe: ({..}, Symbol.t) => 'a = ""
128+
@get_index external getSymbolUnsafe: ({..}, Stdlib_Symbol.t) => 'a = ""
129129

130130
/**
131131
`set(name, value)` assigns a value to the named object property, overwriting the previous value if any. See [Working with Objects on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#objects_and_properties)
@@ -141,7 +141,7 @@ external getSymbol: ({..}, Symbol.t) => option<'a> = ""
141141
@set_index
142142
external set: ({..}, string, 'a) => unit = ""
143143

144-
@set_index external setSymbol: ({..}, Symbol.t, 'a) => unit = ""
144+
@set_index external setSymbol: ({..}, Stdlib_Symbol.t, 'a) => unit = ""
145145

146146
/**
147147
`keysToArray` returns an array of an object's own enumerable string-keyed property names. See [ECMAScript Language Specification](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.keys)

runtime/Option.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ let all = options => {
109109
let acc = []
110110
let hasNone = ref(false)
111111
let index = ref(0)
112-
while hasNone.contents == false && index.contents < options->Array.length {
113-
switch options->Array.getUnsafe(index.contents) {
112+
while hasNone.contents == false && index.contents < options->Stdlib_Array.length {
113+
switch options->Stdlib_Array.getUnsafe(index.contents) {
114114
| None => hasNone.contents = true
115115
| Some(value) =>
116-
acc->Array.push(value)
116+
acc->Stdlib_Array.push(value)
117117
index.contents = index.contents + 1
118118
}
119119
}

runtime/Stdlib.res

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Array = Stdlib_Array
2+
module Date = Stdlib_Date
3+
module Dict = Stdlib_Dict
4+
module Promise = Stdlib_Promise
5+
module RegExp = Stdlib_RegExp
6+
module Result = Stdlib_Result
7+
module Set = Stdlib_Set
8+
module String = Stdlib_String
9+
module Symbol = Stdlib_Symbol
10+
11+
// Aliases for convenience
12+
type date = Date.t

0 commit comments

Comments
 (0)