roc: Destructuring tag with `=` generates parsing error

This currently produces an ARGUMENTS BEFORE EQUALS parsing error, but it should be parsed as a valid def (when used either as a top-level declaration or in an expression):

Email str = Email "blah@example.com"

It should put str in scope and set it equal to "blah@example.com" - just like if I did this:

{ str } = { str: "blah@example.com" }

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

those are the three places a pattern can syntactically occur, yes

Nope! In this case generalization is not a concern, since the โ€œemailโ€ parameter in the function definition is not under a let binding before it accessed in the body. Changing it to be a type error is done the same way as we did in #2299

See #2305, which contains a fix for the parsing error and changes the above to a type error ๐Ÿ˜ƒ

The last line will now cause a typechecking error, but removing Email str = email will fix the type error. There are also ways to fix this (i.e. do a structural subtyping check, like e.g. TypeScript would do).

I see this as a separate question from how = should affect type inference - for example, if I have a function that accepts a [ True, False, Blah ], should I be able to give a Bool to it? I can see arguments for and against that design question, but I think itโ€™s a separate issue! ๐Ÿ˜„