-
Notifications
You must be signed in to change notification settings - Fork 99
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
Abstract Map #497
base: master
Are you sure you want to change the base?
Abstract Map #497
Conversation
For For Another concern with |
Added |
If the user cares about implementation, I think it is best if they choose a specific implementation (such as I think the main point of this class is to hide underlying implementation details from the user, who might have the desire of "I just want to map things, I don't really care how". In this case, I really like that the This also let's us swap out map implementations from under the hood as the best "general case map implementation" changes as the IC changes (e.g. Hash based maps vs trees). |
Ahh didn't think of modules with multiple types... That's a good point. |
We can get |
Create implementation agnostic Map, List, and Set classes. This lets the user not have to think about the implementation of the data structure, and we can pick the best “general case” implementation for each abstract data dat structure.
Currently, if you want to map from
Text
toNat
what you usually do is:The first attempt is to wrap TrieMap in an abstract class:
This is a clear improvement and should be done.
What about the
equal
andhash
arguments?For primitive types, if you have the constructor take in a module that contains these functions, the code becomes very clean because the base library already has these modules defined.
What about mapping from a custom type C to some other type?
This initialization of
map2
is again really nice to read, but the user has to wrap thecompare
andhash
functions in a module. Maybe this is okay, because those functions have to be defined somewhere, so it's just a matter of wrapping their definitions in a module. But it does add a layer of friction (albeit only to users advanced enough to be mapping their own custom types).Alternatively, you can create the module at intialization (e.g. if compare and hash are defined in separate places). But then you get an ugly initialization.
So, for custom types,
map2
is much cleaner but it necessitates users predefining the module (which they probably would do wherever they define the classC
).If modules could be considered subtypes of records, then even
map3
could become clean to use.But wrapping up, I think users can get away with the
map1
andmap2
situations most of the time.map3
is not ideal at all, and if that is actually the common case then a different approach should be taken, or the compiler should be modified to allow formap4
to be used in place ofmap3
.