[External] : Re: Question about circular references

David Alayachew davidalayachew at gmail.com
Tue Jul 4 12:32:00 UTC 2023


Hello Ron,

Thank you for your response!

> > I understand your point, but this requires me to apply
> > an ill fitting model because the language is unable to
> > map the one I actually need.
>
> But why did you decide that you need to do it *with
> records*? It’s not that the language isn’t able to
> represent the graph you want, but that you picked a
> language feature that is meant to represent tuples and
> you’re trying to use it to represent something that isn’t
> a tuple.
>
> Maybe you did it because you want to use pattern-matching
> and records have pattern-matching, but we would like to
> offer pattern-matching for other classes, too.

I actually have no issue going outside of records to do this. A final class
with final public fields would meet my needs just as well. But neither that
final class nor a record can get past this circular reference problem
because Java does not allow a circular reference while maintaining
immutability and direct reference.

By all means, if you can show me a well-fitting solution that accomplishes
this with final classes WITHOUT dipping into indirection I've mentioned
many times above or mutability (or reflection stuff), I'll take my
metaphorical hat and go.

And I understand if that feels like an unreasonable request. I am actually
of the opinion that it is an impossible request. But please, prove me wrong.

And as an aside, please take a look at Gavin's response. He points to
another language that absolutely solved this problem. His F# example
captures an example that meets all my needs for my representation.

> > Are you saying you can accomplish this without
> > indirection, as in without a Map lookup or something
> > equivalent? If so, please demonstrate.
>
> A set of pairs *is* a map (actually, a “multi map", i.e.
> a map from elements to sets). You could implement a map
> from just tuples (as students learn in an introductory FP
> course: you represent the map as a list, and the list is
> a linked list of item-tail pairs, i.e. a cons list) but
> you’re better off just using an existing map
> implementation.

And as I mentioned in a previous response, once you turn this from a set of
nodes to a set of edges with a map lookup, you shoot clarity in the foot to
get something that is possible. As I said, that solution works, but it 100%
does not meet the indirection need I have been describing this entire time.

And if you recall from the last post, this Map lookup strategy that you are
suggesting is the workaround I actually landed on, since it is the most
effective of the ill-fitting solutions. But most effective does not make it
a good fit.

> > Apologies, I was not clear here. My question to you is
> > actually, do you see a problem with the fact that
> > records cannot represent a circular reference to
> > themselves?
>
> No, because records are meant to represent tuples, and
> tuples don’t self-reference.
>
> > According to the definitions I cited earlier,
> > tuples/product types have circular references in their
> > domain of possible values
>
> They don’t. Let’s say that the product type T is defined
> as T := Integer x T. Then a tuple of type T can
> self-reference if and only if T (the second component)
> can self-reference. It’s perfectly consistent, therefore,
> for tuples to not self reference, and Java, like most
> languages with algebraic data types, says tuples don’t
> self-reference. You can’t construct a self-referencing
> instance of T because you’d need a component value that
> is the instance you’re constructing. It also ensures that
> recursions over values always terminate.

Ron, you're using circular logic to avoid the question.

My question was -- records currently cannot self-reference, do you think
that is a problem?

You respond saying -- No, because records are tuples, and tuples cannot
self-reference.

But when I challenge your definition of tuples, saying that they in fact
CAN self-reference, you respond saying -- well, technically they can, but
tuples in Java cannot because the requirement for self referencing is to
contain a component that self-references, that component being the tuple
type itself.

My entire question is asking, do you think it is a problem that records
cannot self-reference, and you say no because records cannot
self-reference, even though tuples can.

Please tell me you see how this is circular logic?

And finally, please look at Gavin's post here --
https://mail.openjdk.org/pipermail/amber-dev/2023-July/008142.html

He has successfully provided an example of circular references that meets
all the points I was talking about.

Thank you for your time and response!
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230704/d9f3d8bc/attachment.htm>


More information about the amber-dev mailing list