rescript-compiler
rescript-compiler copied to clipboard
support @unwarp in @obj
This is extracted from melange.
First commit is a port of melange-re/melange@ff9f8ca (#724) while the second is a refactoring and should be equivalent to melange-re/melange@588f276 (#729)
Thank you for this! I wonder if this really is necessary in ReScript though, now that we have untagged variants. It does require an extra type declaration, but it's easy to just do this:
@unboxed type polyParam = String(string) | Number(float)
@obj
external func: (
~param: string,
~polyParam: polyParam,
) => _ = ""
vs the proposed:
@obj
external func: (
~param: string,
~polyParam: @unwrap
[
| #Str(string)
| #Int(int)
],
) => _ = ""
There's the difference that untagged variants represents all numbers as float, but that's probably more correct anyway given unless unwrap does some magic for actually ensuring it's an int and not a float.