<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><div style="font-family: sans-serif;"><div class="markdown" style="white-space: normal;">
<p dir="auto">On 9 Sep 2022, at 6:41, David Alayachew wrote:</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><p dir="auto">Hello Amber Team,</p>
<p dir="auto">I just wanted to share my experiences with Sealed Types and Data-Oriented
<br>
Programming.</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">Thank you for the well-written note, and for sharing your results.</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><p dir="auto">…
<br>
I used reflection on my sealed interface. I got the sealed type class,
<br>
called Class::getPermittedSubclasses, looped through the subclasses, did an
<br>
unsafe cast from Class<?> to Class<SealedInterface> (because
<br>
::getPermittedSubclasses doesn't do that on its own for some reason???),</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">Good comment.</p>
<p dir="auto">This feels like it <em>might</em> be a simple oversight. If so we might choose to fix it. Or it might well be a conscious decision to limit the impact of reflection on the language proper. The sharpening of <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">String.class</code> to <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">Class<String></code> actually requires complicated moves in the heart of the language, the JLS; such moves are very expensive. Addressing this one would require JLS surgery.</p>
<p dir="auto">Sometimes inconvenient stuff like this, like the no-go for generic enums JEP 301, is due to highly technical roadblocks which are too hard to remove.</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><p dir="auto">…
<br>
I just wish that there was some similar centralized pathway between
<br>
data-oriented programming and the outside world. Some way for me to define
<br>
on my sealed type, a method to give me a pathway to all of the permitted
<br>
subclasses. Obviously, I can build it on my own, but that is where most of
<br>
my pain points came from. Really, having some way to enforce that all of my
<br>
subclasses have a similar class level validation logic and a similar class
<br>
level factory/constructor method is what I am missing.</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">Good summary of a tricky design problem. The images of “islands” is good. We are also talking about a functor between categories, for those who find such ideas illuminating.</p>
<p dir="auto">One thing I would try: Attach grammar fragments or regexps-with-groups to each record using annotations. Then build a tool which uses those annotations to weave a bridge between the islands. It would require some sort of grammar generator. I’d look for a combinator-based library, I think. I don’t work in this area enough to know what’s current. But I admire some Lua-based experiments <a href="https://github.com/vsbenas/parser-gen" style="color: #3983C4;">1</a> and think it’s likely some Java programmer has adapted those ideas to Java and lambdas and records etc. If not maybe it’s time to do so.</p>
<p dir="auto">Thanks!</p>
<p dir="auto">— John</p>
</div></div></body>
</html>