Skip to content

Experiments with Type module #118

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
56 changes: 28 additions & 28 deletions src/Core__Type.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

import * as Caml_option from "rescript/lib/es6/caml_option.js";

function toObjectUnsafe(i) {
return i;
}

function toBoolUnsafe(i) {
return i;
}

function toFloatUnsafe(i) {
return i;
}

function toBigIntUnsafe(i) {
return i;
}

function toStringUnsafe(i) {
return i;
}

function toSymbolUnsafe(i) {
return i;
}

function toFunctionUnsafe(i) {
return i;
}

var isNull = (function(a) { return (a===null); });

var isNullOrUndefined = (function(a) { return (a===null || a===undefined); });
Expand Down Expand Up @@ -119,34 +147,6 @@ function getBySymbol(item, sym) {
}
}

function toObjectUnsafe(prim) {
return prim;
}

function toBoolUnsafe(prim) {
return prim;
}

function toFloatUnsafe(prim) {
return prim;
}

function toBigIntUnsafe(prim) {
return prim;
}

function toStringUnsafe(prim) {
return prim;
}

function toSymbolUnsafe(prim) {
return prim;
}

function toFunctionUnsafe(prim) {
return prim;
}

export {
classify ,
isUndefined ,
Expand Down
14 changes: 7 additions & 7 deletions src/Core__Type.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ type jsType =
| Symbol(Core__Symbol.t)
| Function(function)

external toObjectUnsafe: 'a => object = "%identity"
external toBoolUnsafe: 'a => bool = "%identity"
external toFloatUnsafe: 'a => float = "%identity"
external toBigIntUnsafe: 'a => Core__BigInt.t = "%identity"
external toStringUnsafe: 'a => string = "%identity"
external toSymbolUnsafe: 'a => Core__Symbol.t = "%identity"
external toFunctionUnsafe: 'a => function = "%identity"
let toObjectUnsafe = i => i->Obj.magic
let toBoolUnsafe = i => i->Obj.magic
let toFloatUnsafe = i => i->Obj.magic
let toBigIntUnsafe = i => i->Obj.magic
let toStringUnsafe = i => i->Obj.magic
let toSymbolUnsafe = i => i->Obj.magic
let toFunctionUnsafe = i => i->Obj.magic
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, this isn't what I meant. These are now all just aliases of Obj.magic, and wherever these are used internally you can just substitute with Obj.magic directly.

If you want to export them, then the externals are better because the implementation won't be hidden by the interface and consequently add a function call on every use to what should be a no-op at runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see the problem. I looked at the javascript and there are all these wrappers and we want it to be completely compiled away. I went back to using external %identity in both the resi and the res because that results in less Js output. I find it very weird that the resi file has implementation details like external. If the resi just says let toBoolUnsafe: 'a => bool then this is the output...

function toBoolUnsafe(prim) {
  return prim;
}

In a perfect world wouldn't you be able to only use external in the implementation?


let isNull = %raw(`function(a) { return (a===null); }`)
let isNullOrUndefined = %raw(`function(a) { return (a===null || a===undefined); }`)
Expand Down