Given an unboxed variant like this, Primary has the same runtime representation as Color("primary")
@unboxed
type color =
| @as("primary") Primary
| @as("secondary") Secondary
| Color(string)
This means that a function like
let f = x =>
switch x {
| Color(x) => x
| _ => "not Color"
}
somewhat surprisingly produces "not Color" when called on Color("primary").
However, the optimizer treats this like a regular variant and so constant folding f(Color("primary")) produces "primary", which differs from the result of the generated JS.
Full playground example
Given an unboxed variant like this,
Primaryhas the same runtime representation asColor("primary")This means that a function like
somewhat surprisingly produces
"not Color"when called onColor("primary").However, the optimizer treats this like a regular variant and so constant folding
f(Color("primary"))produces"primary", which differs from the result of the generated JS.Full playground example