Question

I found in some demo code, both *x and x* are used. Sometimes, the star is also used on types, like *int xs. In the help, only the pattern Var* is documented. Is there any difference between putting the star before or after a pattern variable?

Was it helpful?

Solution

Good question. The answer is both yes and no:

  • Yes: The post-fix * is deprecated, since it triggers syntactical ambiguity with post-fix transitive closure in some weird contexts on the expression side of things. This does not happen in patterns, but for consistency we want to have the prefix * mean "splat" in patterns and "splice" in expressions, as dual operators, and remove the post-fix * to avoid confusion.
  • No: when applied to a variable in a pattern they will have the same semantics.

So, please use the prefix + and prefix * when possible to avoid upgrade pain in the future when we remove postfix * and + from the language.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top