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

Feature request: polymorphic variants support inside untagged variants

Open DZakh opened this issue 2 years ago • 2 comments

https://rescript-lang.org/try?version=v11.0.0-beta.4&code=C4TwDgpgBKkHIEMC20C8UDaAoKUA+UAxAM7ABOAlgHYDmO+RVArkgEYRn0GHXAQ0cuRVgHsRAGwgIqQwiNYArCAGNgshGTIIQs5uPFYAuliwABJlVEAPCABMssaI4D6UdAGVqNSQApHiFABKBgBBTW0fDS0QAB5-ZAgAPkCsIA

type typeName = [
  | #string
  | #number
  | #integer
  | #boolean
  | #object
  | #array
  | #null
]

@unboxed
type type_ = Single(typeName) | Array(array<typeName>)

DZakh avatar Sep 11 '23 19:09 DZakh

This can be supported in principle, from a semantic viewpoint. Unsure about where it would fit in terms of implementation. In this case, perhaps as a "string" case to cover all the elements.

CC @zth

cristianoc avatar Sep 13 '23 08:09 cristianoc

I guess we could take all those elements and ensure they don't overlap by treating them as we would treat regular constructors but with the polyvariant value as a pretend @as(). | @as("string") String | @as("number") Number etc.

So if one overlaps we'll need to deny it. And if it's open we need to deny it always I guess.

zth avatar Nov 14 '23 16:11 zth