I've written NonemptyDict and NonemptySet modules! https://github.com/MartinSStewart/Nonempty
My question now is, how do I write tests for them? Also Dict doesn't expose toList or fromList which prevented me from implementing all of the Set API as NonemptySet, is there a reason for not having those functions or is it just a matter of someone making a PR that adds them?
expect
is very new and for testing. Not sure it current state.
As for Dict.toList
, there was a lot of discussion around it, but I don't think we ever made a complete conclusion. The issue is ordering. Two dictionaries could contain the exact same key value pairs, be equal, but when calling toList
, the generated lists would not be equal.
it's pretty decent on a branch now, but today only works for types that are copy (i.e. have no pointers in them)
working on strings/lists/etc as we speak
As for Dict.toList, there was a lot of discussion around it, but I don't think we ever made a complete conclusion. The issue is ordering. Two dictionaries could contain the exact same key value pairs, be equal, but when calling toList, the generated lists would not be equal.
If there are concerns around ordering, shouldn't Dict.keys
and Dict.values
return Set
instead of List
?
Dict
and Set
are still very new. And secretly, Set
is (currently) implemented on top of Dict
(which secretly is implemented on top of List
). So I guess that is why Dict.keys
/Dict.values
currently do not return sets.
also dict values don't need to be comparable/hashable
I think now that we decided on IndexMap
as the backing data structure for Dict
, it's okay to have toList
use whatever order it has internally
the concern previously was that it would be coupled to the hashing function, meaning upgrading the hashing function could break peoples' programs
but with IndexMap
backing it, that's no longer a concern, so I think it's fine if two dictionaries with the same contents have different toList
answers
since insertion ordering is formally part of the semantics of Dict
!
Should there be a Dict.equals and Set.equals for when you do want to see if they are equal independent of insertion order?
Last updated: Jul 05 2025 at 12:14 UTC