“Deriving” functionality for classes and pattern matching on LHS of assignment?
vab2048
vab2048 at gmail.com
Thu Dec 5 09:34:37 UTC 2024
Hi Amber team,
I was wondering about the future of two different features and thought I would just ask the mailing list.
The first feature: deriving instances.
Haskell allows type declarations to derive instances for certain type classes (Eq, Ord, Enum, Bounded, Show, and Read).
Is it possible to get some sort of equivalent for java classes which would allow us to specify to the compiler to auto derive some code. I am thinking about easily auto-generating a toString, equals, hash code etc? We already have a form of this for records, and so bringing it to classes would make a logical next step.
The second feature: pattern matching on LHS of assignment.
Suppose we have this record type:
record Color(byte red, byte green, byte blue) {}
and a static factory method “someFactory” which returns a Color.
Are there any plans to allow us to pattern match at the point of assignment like so:
Color(byte red, byte green, byte blue) color = someFactory();
This would be a great addition to pattern matching.
Regards,
Vikram
More information about the amber-dev
mailing list