Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upProposal: add Dict.intersectBoth #402
Comments
mgold
referenced this issue
Sep 15, 2015
Closed
Proposal: support Haskell-style multiple function bodies with different patterns #1058
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Oct 2, 2015
Member
I am a fan. I'd want it to be something like this:
intersectWith : (a -> b -> c) -> Dict comparable a -> Dict comparable b -> Dict comparable cSo you could do intersect = intersectWith always and intersectBoth = intersectWith (,). I'm not certain about switching the meaning of intersect but I'm doing some core stuff now, so I'll think about this more.
|
I am a fan. I'd want it to be something like this: intersectWith : (a -> b -> c) -> Dict comparable a -> Dict comparable b -> Dict comparable cSo you could do |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
I can live with |
mgold
referenced this issue
Oct 3, 2015
Closed
Bad error messages on incomplete patterns as function arguments #1078
evancz
closed this
Nov 30, 2015
pushed a commit
that referenced
this issue
Mar 1, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Jun 28, 2016
Contributor
I don't think the commit referenced above was ever released, but it's covered by Dict.merge in 4.0.1.
|
I don't think the commit referenced above was ever released, but it's covered by |
mgold commentedSep 9, 2015
I recently found myself writing this code:
This requires the unsafe
(\(Just x) -> x)operation, even though I know it's safe because I'm only looking at keys in the intersection. Although, I was using the union at first, and that blew up in a runtime error, so this is a real runtime error that we can avoid by offering this API inDict:The current
intersectfunction keeps only the values from the first dictionary, even though we know they're also in the second one (because it's the intersection). It's pretty useless in my case:A more extreme change would be to replace it with the function I've called
intersectBoth, since you can get back the old behavior withDict.map (always fst). But if you don't want to do that, adding another function shouldn't be too bad. Because the representation of dictionaries is opaque, this can't be done in a third party library.