Quick question regarding pattern matching
org.openjdk at io7m.com
org.openjdk at io7m.com
Thu Mar 23 13:32:27 UTC 2017
Hello!
I thoroughly enjoyed Brian's talk that was linked to from the original
Amber introduction email. I'm very surprised and happy to learn that
full pattern matching is under consideration as an addition to the
language (I was expecting to only get case analysis as that's somewhat
cheaper and easier to implement).
Couple of small questions:
1. The talk makes no mention of checking matches for exhaustiveness. Is
that just an omission from the talk for brevity? For me, the main
value in pattern matching is the exhaustiveness checks [0].
2. Is the intention of Amber to include some sort of VM-level
infrastructure to allow for languages that implement algebraic data
types to share a common model? For example, if I declare an algebraic
data type in Kotlin, it would be really nice if I could then pattern
match on it in Java or Scala and get the same exhaustiveness checks.
Right now that's obviously not going to happen as they each use a
slightly different representation for ADTs. For example, I believe
the Kotlin compiler adds some protobuf-encoded data to each
compiled ADT class as annotations to mark the class as "sealed".
Users can later get exhaustiveness checks when matching on a value
of that class because the compiler can infer that the class is sealed
from the annotations. A Scala compiler looking at a type compiled by
the Kotlin compiler obviously isn't going to read and/or understand
those annotations.
Regards,
Mark
[0] https://www.youtube.com/watch?v=DM2hEBwEWPc
More information about the amber-dev
mailing list