문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top