rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

support @unwarp in @obj

Open tatchi opened this issue 2 years ago • 1 comments

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)

tatchi avatar Sep 07 '23 22:09 tatchi

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.

zth avatar Sep 19 '23 07:09 zth