-
Notifications
You must be signed in to change notification settings - Fork 178
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
Settle on a consistent strictness for fromList
and fromAscList
#473
Comments
The result of I think we obviously want the two example arguments to |
I think it makes the most sense for |
Yeah, sure. |
Note that -- abridged from Data.Map.Strict.Internal
fromAscList :: Eq k => [(k,a)] -> Map k a
fromAscList xs = fromAscListWithKey (\_ x _ -> x) xs
fromAscListWithKey :: Eq k => (k -> a -> a -> a) -> [(k,a)] -> Map k a and that exhibits the same discrepancy: fromListWithKey (\_ x _ -> x) [(0,undefined),(0,())] = _|_
fromAscListWithKey (\_ x _ -> x) [(0,undefined),(0,())] = fromList [(0,())] We should not make it strict in all given values though because fromListWithKey (\_ _ x -> x) [(0,()),(0,undefined),(0,undefined)] = fromList [(0,())]
fromAscListWithKey (\_ _ x -> x) [(0,()),(0,undefined),(0,undefined)] = fromList [(0,())] looks useful enough for people to rely on (I would rely on the former (at least for performance; imagine expensive computations instead of the bottoms), and if, by accident, the keys turn out to be sorted, I would switch to On the other hand it's consistent with (The last time I thought about this I gave up around here; this |
- the function is rather peculiar in that in the presence of duplicate keys, the first value is not evaluated, but all the others are evaluated. See also #473.
The test added in 9765edd in fact fails for containers 0.6.2.1 (distributed with GHC 8.10.4). It wasn't immediately obvious to me which commit "fixed" it. |
@infinity0: I see only one failing test and that was added in b64a103, testing for extra thunks left behind by |
@int-e Thanks for the explanation, yes I only see that one failing test also. :) |
Agreed, I'll make a PR with this change to settle the inconsistency. |
(Originally described in #340 (comment))
In both
Map
andIntMap
, the strict versions offromList
andfromAscList
show inconsistent and somewhat nonsensical behaviour:[(0, ⊥), (0, 0)]
[(0, 0), (0, ⊥), (0, 0)]
fromList
⊥
⊥
fromAscList
[(0, 0)]
⊥
Map
andIntMap
show the same behaviour as each other.The text was updated successfully, but these errors were encountered: