containers icon indicating copy to clipboard operation
containers copied to clipboard

"implementation is left-biased" - but fromList(With) is not

Open jwaldmann opened this issue 9 years ago • 2 comments

The actual behaviour of fromListWith surprised me, given the general "left-biased" feeling of the library. I think I was expecting that these be equivalent

fromListWith (++) [ (0,"foo"), (1,"bar"), (0,"oof") ]
unionsWith (++) [ singleton 0 "foo", singleton 1 "bar", singleton 0 "oof" ]

but they are not. Perhaps add a warning in the documentation of fromListWith? Currently, you have to parse the example to infer the semantics.

jwaldmann avatar Sep 04 '16 09:09 jwaldmann

Yes, this trips me up too. The idea is that it does a left fold with insert, which indeed is unexpected. Feel free to open a PR, or I'll try to fix it myself.

On Sep 4, 2016 5:32 AM, "jwaldmann" [email protected] wrote:

The actual behaviour of fromList surprised me, given the general "left-biased" feeling of the library. I think I was expecting that these be equivalent

fromListWith (++) [ (0,"foo"), (1,"bar"), (0,"oof") ] unionsWith (++) [ singleton 0 "foo", singleton 1 "bar", singleton 0 "oof" ]

but they are not. Perhaps add a warning in the documentation of fromListWith? Currently, you have to parse the example to infer the semantics.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/haskell/containers/issues/333, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_R9-ewnRWJDxUaBBNkj0KYVn_RwIks5qmpBFgaJpZM4J0fuU .

treeowl avatar Sep 04 '16 14:09 treeowl

Related: https://github.com/haskell-unordered-containers/unordered-containers/issues/264

sjakobi avatar Jul 15 '20 04:07 sjakobi