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

feat: support @mel.as in variant definitions #884

Merged
merged 19 commits into from
Oct 3, 2024

Conversation

anmonteiro
Copy link
Member

@anmonteiro anmonteiro commented Nov 11, 2023

fixes #742

  • still WIP, this just works for constant constructors
  • pattern matching compilation still broken

TODO:

  • pattern matching compilation
  • non-constant constructors
  • check option-like shape
  • extensible variants? (already use MEL_EXN_ID)

@anmonteiro anmonteiro marked this pull request as ready for review September 25, 2024 23:21
@anmonteiro
Copy link
Member Author

anmonteiro commented Sep 29, 2024

edge case to sort out:

type (_, _) x =
  | [] : ('a, 'a) x [@mel.as "lol"]
  | ( :: ) : 'a * ('ty, 'v) x -> ('a -> 'ty, 'v) x

let x : _ x = []

let rec f : type a b. (a, string ref) x -> string =
 fun x -> match x with [] -> "empty" | _ :: xs -> f xs

generates:

function f(_x) {
  while(true) {
    const x = _x;
    if (!x) {
      return "empty";
    }
    _x = x.tl;
    continue ;
  };
}

const x = /* [] */"lol";

@anmonteiro anmonteiro merged commit d136c1d into main Oct 3, 2024
5 checks passed
@anmonteiro anmonteiro deleted the anmonteiro/mel-as-variants branch October 3, 2024 21:03
@dmmulroy
Copy link

dmmulroy commented Oct 3, 2024

LFG

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.

Allow [@mel.as ...] in constructors & record fields
2 participants