-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Feature Proposal: Anonymous Subtype Parameters #16086
Comments
I swear this has been proposed before, but I'm not sure how it was described at the time... |
I think this: #6984 |
@IainNZ I just found that. I think it is identical. I'll close this as a duplicate then. |
you could also note that: |
@vtjnash Almost equiv, but not.
With that said is still might be worth it, until (when and if) point 1 occurs, to do so; to simplify code. |
I've been thinking about this for a while; and I thought I should share the notion.
I'm happy to have it shouted down as a bad idea (particularly if a good explanation is given),
but I figured I should share, incase it is infact a good idea.
We all know that having a container type (etc) contain abstract types is slow.,
thus normal habit for this case, is to instead have containers which contain a consistent, but generic subtype of that abstract type -- because any given container is normally consistent.
All examples here are from real code
EG1
instead of writing
We write:
But that is a little harder to read -- the type of
x
is now spread into two locations.Not too bad though.
Eg 2 Now a more complex function.
Consider:
If the type of
x
and the type ofinput_gradient
are destined to be the same then:But it turns out that, in this case, the type of
x
and the type ofinput_gradient
are not necessarily the same.input_gradient
comes from the greater training procedure -- which is currentlyFloat32
to save on memory.x
however could be aFloat32
or aFloat64
depending on what the input data (from an external source) is (The function always returnsFloat32
).So what we have is now:
That is looking pretty bad, now that I have multiple type parameters.
The type of
x
, and ofinput_gradient
, now each involve cross-referencing two lists.It could perhaps be better with better naming:
So what can we do about it?
The syntax/syntactic sugar I am proposing is that subtypes parameters be allowed without names in the argument types.
Exact syntax, I am not to sure on.
It could be
GenericType{<:AbstractType}
, or perhapsGenericType{_<:AbstractFloat}
,or maybe something else. I'll use the first form for sake of examples.
So
Eg1'.
Before:
After:
Eg2
Before:
After:
This can't replace named type parameters. As it does not allow you to say that multiple of your parameters have the same generic type.
But it does I think clean up the cases where each type parameter is used only once.
I'm not sure if it breaches the "every feature starts at -100 points" test.
But I wanted to present this as an option.
PS: Is their Julep writing guidelines somewhere? I'm happy to reformat this and add additional details.
The text was updated successfully, but these errors were encountered: