My experience with Sealed Types and Data-Oriented Programming
David Alayachew
davidalayachew at gmail.com
Sun Sep 11 04:31:05 UTC 2022
Hello John,
> Thank you for the well-written note, and for sharing your results.
Anytime. I remember watching a video that included Brian Goetz/Ron
Pressler. They mentioned that the most useful and helpful form of feedback
we could provide the Java Team is a run through of us using the preview
features in a non-trivial project, and noting our experiences with it.
> Good comment.
>
> This feels like it *might* 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 String.class to
Class<String> actually requires complicated moves in the heart of the
language, the JLS; such moves are very expensive. Addressing this one would
require JLS surgery
Thank you for the context. I definitely didn't realize the potential cost
of making that cast. It makes a lot more sense why they might have avoided
doing it. Also good to know about the Java Language Specification. I
definitely see what you mean now.
> 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.
That's definitely fair. Admittedly, I was coming from a place of annoyance
when I was talking about the cast and also JEP 301. I need to be more
mindful of the level of complexity and collaboration involved for problems
like that.
> 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.
I just looked up functors, and I'm having a lot of fun with the concepts
behind it. Here's one example from Wikipedia.
> "Let *C* and *D* be categories. A *functor* *F* from *C* to *D* is a
mapping that associates each object [image: X] in *C* to an object [image:
F(X)] in *D"*
On paper, it seems basic and simple, but as a language feature between 2
separate categories of language citizens, that is earth-shattering. It's
also hilarious because that is exactly what I tried to create through
reflection.
I tried to create a Map where each key is one of the permitted subclasses,
and each value is the respective constructor for the permitted subclass. I
had to complicate the Map a bit because of implementation details, but
according to the definition above, I think I made a functor. I will have to
read up on it more.
> 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 1 <https://github.com/vsbenas/parser-gen>
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
I'll give it a shot. I don't know about any grammar generator libraries,
but one other person on this thread mentioned something similar that they
built, so I am sure I'll find something.
Thank you again for your help and insight!
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20220911/c381a9ed/attachment-0001.htm>
More information about the amber-dev
mailing list