Stream: beginners

Topic: NonemptyDict and NonemptySet


view this post on Zulip Martin Stewart (Jul 19 2022 at 19:33):

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?

view this post on Zulip Brendan Hansknecht (Jul 19 2022 at 19:54):

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.

view this post on Zulip Folkert de Vries (Jul 19 2022 at 19:55):

it's pretty decent on a branch now, but today only works for types that are copy (i.e. have no pointers in them)

view this post on Zulip Folkert de Vries (Jul 19 2022 at 19:55):

working on strings/lists/etc as we speak

view this post on Zulip Martin Stewart (Jul 19 2022 at 20:00):

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?

view this post on Zulip Qqwy / Marten (Jul 19 2022 at 20:03):

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.

view this post on Zulip Folkert de Vries (Jul 19 2022 at 20:03):

also dict values don't need to be comparable/hashable

view this post on Zulip Richard Feldman (Jul 19 2022 at 20:04):

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

view this post on Zulip Richard Feldman (Jul 19 2022 at 20:05):

the concern previously was that it would be coupled to the hashing function, meaning upgrading the hashing function could break peoples' programs

view this post on Zulip Richard Feldman (Jul 19 2022 at 20:05):

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

view this post on Zulip Richard Feldman (Jul 19 2022 at 20:06):

since insertion ordering is formally part of the semantics of Dict!

view this post on Zulip Martin Stewart (Jul 19 2022 at 20:17):

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