-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add sneaky invoke example (from Slack) #38
Conversation
examples/sneakyinvoke.jl
Outdated
|
||
concrete(::Type{Type{T}}) where {T} = T | ||
|
||
function _sneaky_transform(f::Type, Types::Type{<:Tuple}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to split this out? I can see this being useful for development but for show it off we should probably make it as simple as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all. But accessing parameters[1]
just felt kind of ugly to me. OTOH, for a show off, it shows the semantics much more clearly: that we need to get rid of a level of Type
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For that you need concrete
but I don't see that it needs _sneaky_transform
to be split out, because that's not doing any unwrapping, it just passes through arguments without modification.
It could work well to just do @dynamo function sneakyinvoke(f, Type{T}, ...) where T<:Tuple
. The dynamo type signature refers to the unwrapped parameters so that might be a cleaner way to unwrap that avoids the utility functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong above due to #41, but I've pushed a fix which makes the following work:
@dynamo function sneakyinvoke(f, ::Type{T}, args...) where T<:Tuple
ir = IR(f, T.parameters...)
argument!(ir, at = 2)
return ir
end
I think this is a slightly more idiomatic way to do the unwrapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also give this example:
println("Get around overly restrictive type annotations")
@show sneakyinvoke((x::Float64) -> x + 1, Tuple{Float64}, 1)
Hope you don't mind that I made those small tweaks. Thanks a lot for working out this example! |
Sure I don't mind. And about #41: of course that's exactly why I wrote it that way :) In fact, I have just always accepted this limitation and never considered it a missing feature. |
I cleaned it up a bit as well.