-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make visitors able to visit any domain type #66
Comments
I'm curious how this is different than using accept? I believe the intention of an
|
If visitors have parameterized return types like discussed here -- #123 then you include the parameterized return type and context objects in the accept. The current state of visitors/transformers/etc. is all confusing and should be consolidated to a single abstraction to avoid this confusion |
Here's a modified example from an old project interface IRVisitor<R, C> {
fun visit(node: IRNode, ctx: C): R? = defaultVisit(node, ctx)
// "reverse" visit for nodes A, B extending X
// you are proposing generating one of these for each sum type and the whole domain
fun visit(node: IRNodeX, ctx: C): R? = when (node) {
is IRNodeA -> visit(node, ctx)
is IRNodeB -> visit(node, ctx)
}
// .... removed
}
sealed interface IRNode {
override fun <R, C> accept(visitor: IRVisitor<R, C>, ctx: C): R? = visitor.visit(this, ctx)
} Then given some IRVisitor and an arbitrary IRNode, we can call accept on the IRNode to invoke the appropriate visitor method via function overloading. Am I missing something here? |
You call |
Given a simple domain:
For the Kotlin target we get something like:
However, none of the generated visitors can accept instances of
SimpleNode
. This is a problem if you have an instance ofSimpleNode
and want to send it thru one of the visitors. The user has to write awhen
statement and dispatch to the appropriate visitor method. PIG's own tests (withinPermuteTransformTests
) for example contain the following code:This is potentially a pain point for users and should really be part of the generated visitors:
As part of this we should consider if it is possible and advisable to make
SimpleNode
asealed
class.SimpleNode
)sealed
, and if so, make it so.DomainVisitorBase
implementationsDomainVisitorFoldBase<T>
implementationsDomainVisitorTransformBase
implementationswhen
block (shown in the example above) fromPermuteTransformTests
The text was updated successfully, but these errors were encountered: