Allowing reserved words in polymorphic variants

I’m working on porting my websocket implementation from reason to rescript, and remembered how much this annoyed me:

external on: (
    | #close((int, string) => unit)
    | #message(string => unit)
    |"open") #open_(unit => unit)
    | #ping(Node.Buffer.t => unit)
    | #pong(Node.Buffer.t => unit)
    | #error(Dom.errorEvent => unit)
) => t = "on"

Is there a reason that polymorphic variants can’t use reserved words, since afaik they’re always marked by a #? Or is it something that just hasn’t been deemed necessary.


Indeed I think that the parser should potentially be able to be disambiguate this. Since ReScript is now owning their own parser is this something that can be improved in the future?

You can write #\"open". See for more context.

In the future we will support nicer syntax and allow reserved words without the escaping mechanism. But this will likely take a while.


Seeing as how you’d have to use the backslash at use site as well, this isn’t much better than just using #open_, unless I’m mistaken. Ah well.