Skip to content

[PoC] Allowing ad hoc aliasing of an or pattern of literals into a polyvariant#7801

Draft
zth wants to merge 1 commit into
masterfrom
implement-alias-to-polyvariant
Draft

[PoC] Allowing ad hoc aliasing of an or pattern of literals into a polyvariant#7801
zth wants to merge 1 commit into
masterfrom
implement-alias-to-polyvariant

Conversation

@zth

@zth zth commented Aug 24, 2025

Copy link
Copy Markdown
Member

Now that the runtime represenation of polyvariants is stable and well defined, we can allow aliasing or patterns of literals into a polyvariant if we want, since we can guarantee that if it matches it has been refined to the provided runtime representation.

Example:

type abc = [#a | #b | #c]

let useABC = (x: abc) =>
  switch x {
  | #a => 1
  | #b => 2
  | #c => 3
  }

let fromString = s =>
  switch s {
  | ("a" | "b" | "c") as #...f => useABC(f) // `f` will be a polyvariant of the literals matched on in the pattern. So `[#a | #b | #c]`.
  | _ => 0
  }

Notes

For the implementation, we might need to check extra that the literals are valid as polyvariant constructors.

@pkg-pr-new

pkg-pr-new Bot commented Aug 24, 2025

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7801

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7801

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7801

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7801

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7801

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7801

commit: 487cea6

@zth zth added this to the v12.1 milestone Dec 4, 2025
@cknitt cknitt modified the milestones: v12.1, v13 Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants