Skip to content

[WIP] Rescript v11 #135

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rescript/core",
"version": "0.5.0",
"version": "1.0.0",
"sources": [
{
"dir": "src",
Expand Down
24 changes: 13 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rescript/core",
"version": "0.5.0",
"version": "1.0.0",
"scripts": {
"clean": "rescript clean",
"build": "rescript",
Expand All @@ -23,10 +23,10 @@
"src/**/*.mjs"
],
"peerDependencies": {
"rescript": "^10.1.0 || ^11.0.0-alpha.0 || next"
"rescript": ">= 11.0.0-beta.3"
},
"devDependencies": {
"rescript": "10.1.4",
"@babel/code-frame": "7.18.6"
"@babel/code-frame": "7.18.6",
"rescript": "11.0.0-beta.3"
}
}
2 changes: 1 addition & 1 deletion src/Core__Error.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var $$TypeError = {};
var $$URIError = {};

function panic(msg) {
throw new Error("Panic! " + msg + "");
throw new Error("Panic! " + msg);
}

export {
Expand Down
12 changes: 6 additions & 6 deletions src/Core__JSON.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ function classify(value) {
switch (match) {
case "[object Array]" :
return {
TAG: /* Array */4,
TAG: "Array",
_0: value
};
case "[object Boolean]" :
return {
TAG: /* Bool */0,
TAG: "Bool",
_0: value
};
case "[object Null]" :
return /* Null */0;
return "Null";
case "[object Number]" :
return {
TAG: /* Number */2,
TAG: "Number",
_0: value
};
case "[object String]" :
return {
TAG: /* String */1,
TAG: "String",
_0: value
};
default:
return {
TAG: /* Object */3,
TAG: "Object",
_0: value
};
}
Expand Down
10 changes: 9 additions & 1 deletion src/Core__JSON.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
type t = Js.Json.t
@unboxed
type rec t = Js.Json.t =
| @as(false) False
| @as(true) True
| @as(null) Null
| String(string)
| Number(float)
| Object(Js.Dict.t<t>)
| Array(array<t>)

@raises @val external parseExn: string => t = "JSON.parse"
@raises @val external parseExnWithReviver: (string, (string, t) => t) => t = "JSON.parse"
Expand Down
12 changes: 10 additions & 2 deletions src/Core__JSON.resi
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ Functions for interacting with JSON.
*/

/**
A type representing a JSON object.
A type representing a valid JSON value.
*/
type t = Js.Json.t
@unboxed
type rec t = Js.Json.t =
| @as(false) False
| @as(true) True
| @as(null) Null
| String(string)
| Number(float)
| Object(Js.Dict.t<t>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Js.Dict.t assumes keys are stings, but they can also be Symbols, according to the spec, and in practice any other primitive type as well. Although I'm not sure the latter is a significant difference since primitive values automatically coerce to and from string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good point. Currently you'll need to take care of stringifying the keys yourself.

| Array(array<t>)

/**
`parseExn(string)`
Expand Down
4 changes: 2 additions & 2 deletions src/Core__List.res
Original file line number Diff line number Diff line change
Expand Up @@ -870,14 +870,14 @@ let partitionU = (l, p) =>
nextX,
switch nextY {
| list{_, ...tail} => tail
| list{} => assert false
| list{} => assert(false)
},
)
} else {
(
switch nextX {
| list{_, ...tail} => tail
| list{} => assert false
| list{} => assert(false)
},
nextY,
)
Expand Down
2 changes: 1 addition & 1 deletion src/Core__Null.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type t<'a> = Js.Null.t<'a>
@unboxed type t<'a> = Js.Null.t<'a> = Value('a) | @as(null) Null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I like this better than the christmas presents 😁 Although null is definitely also a value, it's hard to think of a name that makes the distinction accurately.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😀🌲

Yeah the naming wasn't easy. We chose between this and Present, and I personally think Value is slightly clearer, although I do agree with your point.


external asNullable: t<'a> => Core__Nullable.t<'a> = "%identity"

Expand Down
3 changes: 2 additions & 1 deletion src/Core__Null.resi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ If you also need to cover `undefined`, check out `Nullable` instead.
/**
A type representing a value that can be either `'a` or `null`.
*/
type t<'a> = Js.Null.t<'a>
@unboxed
type t<'a> = Js.Null.t<'a> = Value('a) | @as(null) Null

/**
Converts a `Null.t` into a `Nullable.t`.
Expand Down
2 changes: 1 addition & 1 deletion src/Core__Nullable.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type t<'a> = Js.Nullable.t<'a>
@unboxed type t<'a> = Js.Nullable.t<'a> = Value('a) | @as(null) Null | @as(undefined) Undefined

external null: t<'a> = "#null"

Expand Down
3 changes: 2 additions & 1 deletion src/Core__Nullable.resi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Primarily useful when interoping with JavaScript when you don't know whether you
Type representing a nullable value.
A nullable value can be the value `'a`, `null` or `undefined`.
*/
type t<'a> = Js.Nullable.t<'a>
@unboxed
type t<'a> = Js.Nullable.t<'a> = Value('a) | @as(null) Null | @as(undefined) Undefined

/**
The value `null`.
Expand Down
34 changes: 17 additions & 17 deletions src/Core__Result.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as Curry from "rescript/lib/es6/curry.js";

function getExn(x) {
if (x.TAG === /* Ok */0) {
if (x.TAG === "Ok") {
return x._0;
}
throw {
Expand All @@ -13,17 +13,17 @@ function getExn(x) {
}

function mapOr(opt, $$default, f) {
if (opt.TAG === /* Ok */0) {
if (opt.TAG === "Ok") {
return Curry._1(f, opt._0);
} else {
return $$default;
}
}

function map(opt, f) {
if (opt.TAG === /* Ok */0) {
if (opt.TAG === "Ok") {
return {
TAG: /* Ok */0,
TAG: "Ok",
_0: Curry._1(f, opt._0)
};
} else {
Expand All @@ -32,78 +32,78 @@ function map(opt, f) {
}

function flatMap(opt, f) {
if (opt.TAG === /* Ok */0) {
if (opt.TAG === "Ok") {
return Curry._1(f, opt._0);
} else {
return opt;
}
}

function getOr(opt, $$default) {
if (opt.TAG === /* Ok */0) {
if (opt.TAG === "Ok") {
return opt._0;
} else {
return $$default;
}
}

function isOk(x) {
if (x.TAG === /* Ok */0) {
if (x.TAG === "Ok") {
return true;
} else {
return false;
}
}

function isError(x) {
if (x.TAG === /* Ok */0) {
if (x.TAG === "Ok") {
return false;
} else {
return true;
}
}

function equal(a, b, f) {
if (a.TAG === /* Ok */0) {
if (b.TAG === /* Ok */0) {
if (a.TAG === "Ok") {
if (b.TAG === "Ok") {
return Curry._2(f, a._0, b._0);
} else {
return false;
}
} else if (b.TAG === /* Ok */0) {
} else if (b.TAG === "Ok") {
return false;
} else {
return true;
}
}

function compare(a, b, f) {
if (a.TAG === /* Ok */0) {
if (b.TAG === /* Ok */0) {
if (a.TAG === "Ok") {
if (b.TAG === "Ok") {
return Curry._2(f, a._0, b._0);
} else {
return 1;
}
} else if (b.TAG === /* Ok */0) {
} else if (b.TAG === "Ok") {
return -1;
} else {
return 0;
}
}

function forEach(r, f) {
if (r.TAG === /* Ok */0) {
if (r.TAG === "Ok") {
return Curry._1(f, r._0);
}

}

function mapError(r, f) {
if (r.TAG === /* Ok */0) {
if (r.TAG === "Ok") {
return r;
} else {
return {
TAG: /* Error */1,
TAG: "Error",
_0: Curry._1(f, r._0)
};
}
Expand Down
18 changes: 9 additions & 9 deletions src/Core__Type.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@ function classify(value) {
switch (match) {
case "[object BigInt]" :
return {
TAG: /* BigInt */6,
TAG: "BigInt",
_0: value
};
case "[object Boolean]" :
return {
TAG: /* Bool */0,
TAG: "Bool",
_0: value
};
case "[object AsyncFunction]" :
case "[object Function]" :
case "[object GeneratorFunction]" :
return {
TAG: /* Function */4,
TAG: "Function",
_0: value
};
case "[object Null]" :
return /* Null */0;
return "Null";
case "[object Number]" :
return {
TAG: /* Number */2,
TAG: "Number",
_0: value
};
case "[object String]" :
return {
TAG: /* String */1,
TAG: "String",
_0: value
};
case "[object Symbol]" :
return {
TAG: /* Symbol */5,
TAG: "Symbol",
_0: value
};
case "[object Undefined]" :
return /* Undefined */1;
return "Undefined";
default:
return {
TAG: /* Object */3,
TAG: "Object",
_0: value
};
}
Expand Down
Loading