Nemerle and extra-powerful pattern matching

Hey guys,

I was just watching this awesome Nemerle presentation on pattern matching:

  http://blog.tkachev.com/2012/07/nemerle-pattern-matching-and-algebraic.html

and remembered reading that Jetbrains recently picked up the Nemerle team, I’d love to see some Nemerle love find its way down into Kotlin - having such awesome pattern matching would truely put Kotlin in a leage above the rest.

I don't see much use in powerful pattern matching for a normal user. It may be very handy for a compiler writer, but only very few of us do compilers... What we have now is flow-based typing:

https://github.com/abreslav/introduction-to-kotlin/blob/master/kotlin-examples/src/_06_smart_cast/Eval.kt#L52

It seems fine in the majority of the real-life cases, and full pattern matching is complex and cumbersome enough not to have it for the sake of rest of the cases.

Hrm, the flow typing really only goes some of the way and gives you switching on class type, which does clean up a lot of cases sure, but I can see plenty of areas in code I've written that would be much nicer to refactor/work with with some more pattern matching love.

Some immediate things come to mind like a billing system where things switch behaviour based on being $0 amount, or single/multi-month billing.

Maybe a compromise along the lines of Clojures multi-methods, which I think has been discussed elsewhere/before, where one when’s an expression, or something like the union/alias idea I posted in another thread ( which gets around some of the static typing issues I can see with any variation of expression matching here ).

Maybe I just want too much :slight_smile:

Some immediate things come to mind like a billing system where things switch behaviour based on being $0 amount, or single/multi-month billing.

What pattern matching functionality could help you there? To me it seems that a simple conditional would do the job with no problem.

Maybe a compromise along the lines of Clojures multi-methods

Do you mean that the problem is to check the type of two or more things at once? You can do that in "when":

``

when {
  x is Foo && y is Bar -> …
  …
}

Maybe I just want too much :)

Maybe you just don't really need it :)