Generalized pattern matching

I'm not sure to achieve this exactly, but I think we should aim to come up with a solution that unifies the various kinds of pattern matching we have:

  • conditional destructuring: case let (x, y) = getPoint()
  • ~= operator (implicitly used in some case statements)
  • <- operator (from the proposal).

I'm also not a fan of using a Pattern protocol, because that precludes the use of anonymous closures as patterns. Oddly enough, Java's batshit crazy lambdas-as-instantiation-of-an-anonomous-inner-subclass approach would work well here.

Perhaps the right side of this <- operator can be any (In) -> Out? function, which could either be an anonymous closure e.g. let i <- { Int(str) }, or any Pattern's match function could be used: let x, y <- PointPattern.match, which is itself a (In) -> Out? function

1 Like