Open
Description
The following ReScript code
type status1 = OPEN | CLOSED
let isOpen1 = (status: status1) =>
switch status {
| OPEN => true
| CLOSED => false
}
type status2 = [#OPEN | #CLOSED]
let isOpen2 = (status: status2) =>
switch status {
| #OPEN => true
| #CLOSED => false
}
creates the following JS output:
function isOpen1(status) {
if (status === "OPEN") {
return true;
} else {
return false;
}
}
function isOpen2(status) {
return status === "OPEN";
}
So there is some optimization applied for polymorphic variants that is not applied for normal variants.