-
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
Too restrictive type signatures #538
Comments
While I agree the signatures are unfortunate, your proposed replacements simply won't work. Can you understand why? Try implementing them using |
Ah, I've overlooked the case where it's just an insert instead of an "update". Then I feel like another set of functions that "upsert" (update/insert) would be helpful. e.g.:
|
I've been thinking the natural options are whatever :: Ord k => b -> (b -> b) -> k -> Map k b -> Map k b
whatever' :: Ord k => (Maybe b -> b) -> k -> Map k b -> Map k b |
Is there anything that ought to be addressed in this issue? Currently I'm a bit confused. |
@sjakobi, I think this is really just another instance of people complaining about how wretched the |
I actually wasn't aware that
I do like this type though. Maybe we should give the implementation in the documentation for I'm not opposed to exporting it either. The issue of |
Personally, I have to look up the |
OK. I guess we can't change or get rid of Is using Otherwise we need a proposal for an addition – possibly with the mentioned |
Maybe so. Should we perform manual worker/wrapper with unboxed sums to try to improve |
My understanding of the optimizations that GHC can apply is unfortunately way too vague for me to give a useful response! :/ Is it important that we consider performance first though? How about we try to nail the ergonomics first and then see whether more performance work is needed?! (Also, is #523 related?!) |
The idea is that we can write -- Unlifted newtypes exist now, right?
newtype Maybe# a = Maybe# (# (##) | a #)
pattern Nothing# :: Maybe# a
pattern Nothing# = Maybe# (# (##) | #)
pattern Just# :: a -> Maybe# a
pattern Just# v = Maybe# (# | v #)
alter :: Ord k => (Maybe a -> Maybe a) -> k -> Map k a -> Map k a
alter f = alter# $ \case
Nothing# _ -> case f Nothing of
Nothing -> Nothing#
Just v -> Just# v
{-# INLINE alter #-}
alter# :: Ord k => (Maybe# a -> Maybe# a) -> k -> Map k a -> Map k a The idea is that there's a good chance GHC will inline |
Kind of late, but I found this issue again and think that what I was looking for initially was something like: But I guess that's just a bit more specific upsert :: Ord k => (a -> Maybe b -> b) -> k -> a -> Map k b -> Map k b
upsert f k newVal = alter (Just . f newVal) k |
@Vlix Intuitively I'd say that it's a bit weird to So far I don't really see a convincing case for extending the API. For now I'd suggest to use |
Yeah, me neither, but I just wanted to further explain what this Issue was started with: me erroneously assuming So this issue can be closed if it isn't for anything else. |
I feel that at least the following functions should have less restrictive type signatures:
C) {current signature}
P) {proposed signature}
The text was updated successfully, but these errors were encountered: