# API suggestion for dict/set in core; custom compare functions

**URL:** <https://discourse.elm-lang.org/t/api-suggestion-for-dict-set-in-core-custom-compare-functions/807>\
**Category:** Request Feedback\
**Created:** [March 7, 2018, 6:38am UTC](https://discourse.elm-lang.org/t/api-suggestion-for-dict-set-in-core-custom-compare-functions/807 "2018-03-07T06:38:29Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![opvasger](https://avatars.discourse-cdn.com/v4/letter/o/8e8cbc/32.png) [@opvasger](https://discourse.elm-lang.org/u/opvasger)\
**Post date:** [March 8, 2018, 5:34am UTC](https://discourse.elm-lang.org/t/api-suggestion-for-dict-set-in-core-custom-compare-functions/807/21 "2018-03-08T05:34:48Z")

</div>

> [@MarkHamburg](#):
>
> Sorry I missed the fact that you had tied specification of the comparison function to construction. I’ll blame insufficient caffeine.

Haha, no worries 🙂

> [@MarkHamburg](#):
>
> But you do then have a runtime exception issue when comparing dictionaries or sets for equality because those will now contain a reference to the comparison function and comparing two non-identical functions in Elm generates a runtime exception. In other words: Dict.empty comparison1 == Dict.empty comparison2 could throw a runtime exception.

I missed this part - I can’t think of any way around function comparison here 😕 hmm…

---

<div class="post-metadata">

**Author:** ![mattpiz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattpiz/32/860_2.png) [@mattpiz](https://discourse.elm-lang.org/u/mattpiz)\
**Post date:** [March 8, 2018, 11:24am UTC](https://discourse.elm-lang.org/t/api-suggestion-for-dict-set-in-core-custom-compare-functions/807/22 "2018-03-08T11:24:42Z")

</div>

> [@opvasger](#):
>
> I missed this part - I can’t think of any way around function comparison here 😕 hmm…

You could provide you own equality function like `MyDict.equal`, but no guaranty that users are not going to do `dict1 == dict2`. Except if elm compiler detect function equality attempts one day

[Previous page](https://discourse.elm-lang.org/t/api-suggestion-for-dict-set-in-core-custom-compare-functions/807.md?page=1)
