-
Notifications
You must be signed in to change notification settings - Fork 28
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 similar_type
#54
base: master
Are you sure you want to change the base?
Add similar_type
#54
Conversation
Codecov Report
@@ Coverage Diff @@
## master #54 +/- ##
==========================================
- Coverage 74.00% 73.76% -0.25%
==========================================
Files 19 19
Lines 1712 1738 +26
==========================================
+ Hits 1267 1282 +15
- Misses 445 456 +11
Continue to review full report at Codecov.
|
So I think I'm missing some context here to exactly understand what interface you're building here. Are you saying that this So you want another word like Generically, do we have a problem here of a cross product of possible traits which the "similar" output containers may or may not share with the template
Well I guess you could qualify it with the module, but needing to use |
Yes, exactly. Except I’m imagining precisely three “factories”:
There would be no traits involved beyond the fact that 2 is useless without mutability and 3 is useless without insertability, so you wouldn’t define the type-domain functions for those cases. |
Ok cool 👍
So these are the cases you think you need for the particular case of indexable containers (well, dictionaries) of which AbstractArray would be a subtype in principle? Hence the connection to StaticArrays? Btw I don't actually want to involve traits. I only mention that thought because I'm unsure three classes of constructors really cover things (eg, looking at https://github.com/JuliaArrays/ArrayInterface.jl there's a disturbing variety of special purpose traits). |
Yeah. My thoughts are: When you NEED certain traits then you are going to have to use less generic code. The fact is that there is always more traits to be created that you don't know about. I'm not sure a If you just want to write generic code that builds "a container" which holds arbitrary data I think those 3 options will cover the vast majority of cases. Currently
I believe all those examples are all outside the scope of "I want generic code that populates containers with arbitrary values". These are cases where you want non-generic code. Or generic code that is more specialized than "I've got a container". |
The operation is a bit like |
Could well be true. I guess I don't have a strong opinion one way or another about this. It should be cleaner in StaticArrays to call Though typically in
|
Arrays are interesting. The keys are sometimes unnecessary, right? Though you might want something for offset arrays. And higher dimensional arrays. And static arrays (the sizes are specified in Indices (and UnitRange and CartesianIndices and so-on) could use two-argument forms of |
Yeah, me neither. It just seemed like immutable container support was always missing, and unnecessarily so... I'm thinking of this more as an experiment at this point. |
To add to the list of function names which are sort of like what you want here... there's also |
Keno has just updated the |
This adds a new
similar_type
type-level function for giving the return type ofsimilar
. It is modelled similarly toempty_type
. There are fixups for bothempty
,similar
and the constructors.There is an expectation that insertable containers have a zero-argument constructor (for constructing an empty container) and that settable dictionaries have a 2-argument constructor of the form
DictType(indices, undef)
. These are assumed if you implementempty_type
orsimilar_type
for your custom container.In future I wish to add a third "factory" function like
empty
andsimilar
for situations where both the keys and values are known. This is most useful for immutable dictionaries but the result does not have to be immutable - it's just a generic pattern for this case, that allow generic algorithms to be built upon. Such dictionaries would have two-argument constructors of the formDictType(indices, values)
and there would be a matching type-domain function. (Note: for indices there would be a single argument constructor of the formIndType(indices)
).CC @c42f - I'm thinking this "new" unimplemented functionality is probably the "correct" way to do the StaticArrays pattern of
similar_type
and constructor requirements. I'm lost what to call it, though - placeholders for argument's sake would benew(old_container, new_indices, new_values)
andnew_type(OldType, NewKeyType, NewElType)
but I'm not sure we can think of a better word thannew
? (Plusnew
wouldn't be callable from inner constructors, which would be a weird corner case to have).(This is intended to close #51)