<div dir="ltr">On Sat, Jun 8, 2024 at 7:21 PM Sam Carlberg <<a href="mailto:sam@slfc.dev">sam@slfc.dev</a>> wrote:<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-family:Arial,sans-serif">The core part of the library is a <code>Unit</code> </span><font dir="auto" face="Arial, sans-serif">class with a recursive self type</font></blockquote><div><br></div><div>Side note/digression on "self type"...</div><div><br></div><div>I've also wished for a simpler way to create self types that doesn't spam your entire type hierarchy with a new generic type variable.</div><div><br></div><div>For example, instead of this:</div><div><br></div><div><div style="margin-left:40px"><span style="font-family:monospace">public interface Builder<T, B extends Builder<T, B>> {</span><br><span style="font-family:monospace">    B withFoo(Foo f);</span><br><span style="font-family:monospace">    B withBar(Bar b);</span><br><span style="font-family:monospace">    T build();</span><br><span style="font-family:monospace">}</span><br></div><div><br></div><div>syntactic sugar could allow you to do something like this:<br></div><br><div style="margin-left:40px"><span style="font-family:monospace">public interface Builder<T> {</span><br><span style="font-family:monospace">    this.class withFoo(Foo f);</span><br><span style="font-family:monospace">    this.class withBar(Bar b);</span><br><span style="font-family:monospace">    T build();</span><br><span style="font-family:monospace">}</span></div></div><div> </div><div>The compiler would then assign the return value of any withFoo() invocation to have the exact same (fully generified) type as the type of the receiver, and any implementation of withFoo() would just have to return an object with type compatible with Builder<T>.<br></div><div><br></div><div>I don't see any fundamental reason why this couldn't work but I could be missing something.<br></div><div><br></div><div>-Archie<br></div></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>