<html><head></head><body><div dir="auto">In the future, we want to retrofit primitive to be value types.<br><br>Type classes are one of the solutions for that.<br><br>Rémi<br></div><br><br><div class="gmail_quote"><div dir="auto">On August 8, 2025 9:12:28 PM UTC, David Alayachew <davidalayachew@gmail.com> wrote:</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="auto"><div>Woah, Type Classes!<div dir="auto"><br></div><div dir="auto">Ok, design talk aside, are you saying type classes are something you all have decided to do? Is that a feature, even if only for value classes, that we can safely assume is on the road map?</div><div dir="auto"><br></div><div dir="auto">All previous discussion on this made it sound like it's being strongly considered, but not on the road map.</div><br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Fri, Aug 8, 2025, 4:02 PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is a valid observation, but you are getting way ahead of yourself.  My talk this week was about general mechanisms; we are not designing this feature yet, and discussions about it are premature (and likely counterproductive, as people chime in with questions about something that is not yet designed.)<br>
<br>
> On Aug 8, 2025, at 12:06 PM, Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank" rel="noreferrer">forax@univ-mlv.fr</a>> wrote:<br>
> <br>
> Hello,<br>
> for those who where not at the JVMLS, it may make sense to re-read this email later,<br>
> when the talk of Brian on Type class / witness is visible on youtube.<br>
> I write this now because i'm sure i will totally forget about that in few days.<br>
> <br>
> During the talk, Brian said that witness are restricted to be used only by value classes so we avoid the operator overloading hell that you can see in other languages.<br>
> <br>
> I think this restriction can be bypassed.<br>
> <br>
> The problem is that you can always wrap any class into a value class organized as a monad (containing a superposition of states) thus bypassing that restriction.<br>
> <br>
> <br>
> As an example, let say we want to abuse of the >> operator to emulate C++ iostream.<br>
> Let suppose we have this witness interface defined in the JDK (it is by example used by Integer)<br>
> <br>
> witness interface BitwiseNumeric<V> {<br>
>  V rightShift(V v1, V v2);<br>
> <br>
>  // other methods<br>
> }<br>
> <br>
> And the witness interface for exact conversion also defined in the JDK<br>
> <br>
> witness interface Conversion<U, V> {<br>
>  U convert(V value);<br>
> }<br>
> <br>
> <br>
> So the trick is to create a value class that encode either a Writer or any value you want to add to the writer as a monad,<br>
> The exact conversion is used to wrap any value into the IOStream, the righShift is used to consume the wrapped value using a side-effect.<br>
> <br>
> value class IOStream {<br>
> private final Writer writer;<br>
> private final Object o;<br>
> <br>
> private IOStream(Writer writer, Object o) { this.writer = writer; this.o = o; super(); }<br>
> <br>
> public IOWriter(Writer! writer) { this(writer, null); }  <br>
> <br>
> public static final witness BitwiseNumeric<IOStream!> BITWISE_NUMERIC = new BitwiseNumeric<>() {<br>
>   public IOStream! rightShift(IOStream! v1, IOStream! v2) {<br>
>     if (v1.writer == null || v2.writer != null) {<br>
>       throw new ISE();<br>
>     }<br>
>     v1.writer.append("" + v2.o);<br>
>     return v1;<br>
>   }<br>
> <br>
>   // other methods throw UnsupportedOperationException<br>
> };<br>
> <br>
> public static final witness Conversion<IOStream!, Integer!> FROM_INTEGER = new Conversion<>() {<br>
>   IOStream! convert(Integer! value) {<br>
>     return new IOStream(null, value);<br>
>   }<br>
> };<br>
> }<br>
> <br>
> So one can write<br>
>  IOStream stream = new IOStream(writer);<br>
>  var _ = stream >> 2 >> 3;<br>
> <br>
> I think this is a general mechanism so any operator can be abused that way.<br>
> <br>
> regards,<br>
> Rémi<br>
<br>
</blockquote></div></div></div>
</blockquote></div></body></html>