RFR: [type-classes] Initial work to enable type-classes mediated operator support [v2]
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Jan 26 16:49:35 UTC 2026
On Sat, 24 Jan 2026 03:46:55 GMT, Joe Darcy <darcy at openjdk.org> wrote:
> @mcimadamore , what are the conditions to allow to a class to participate in having a witness, is being a value class sufficient?
>
> I was working on update Bfloat16 to have a witness for StandardFloatingPoint, but the client code wasn't recognizing the operators as valid for Bfloat16 arguments. Perhaps recognizing as allowing both Numerical and Orderable operators isn't work yet.
>
> After switching to a Numerical witness in a Bfloat16 value class, the code was accepted by the compiler, but ran into VerifyErrors at runtime. I'll send you more information off-list. Thanks.
I've addressed the verifier issues here:
https://git.openjdk.org/valhalla/pull/1968
As for the other issue you mentioned -- note that if you want to apply an operation that belongs to the Numerical class, such as `+`, you need to have a witness for Numerical. In other words, Bfloat16 needs to have witnesses for both Numerical, StandardFloating point and Orderable.
At the moment "type class extension" is a bit clunky, so the various witnesses have to be provided and wired manually, as shown in this test:
https://github.com/mcimadamore/valhalla/blob/2b56b03d734a2f82f9ef978d11811245ddc30a1d/test/langtools/tools/javac/typeClasses/TypeClassesOperatorResolutionTest.java#L34
-------------
PR Comment: https://git.openjdk.org/valhalla/pull/1948#issuecomment-3800584068
More information about the valhalla-dev
mailing list