Skip to content
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

support @unwarp in @obj #6395

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

tatchi
Copy link
Contributor

@tatchi tatchi commented Sep 7, 2023

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)

@zth
Copy link
Collaborator

zth commented Sep 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants