Skip to content
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

Use alterF machinery? #14

Open
treeowl opened this issue Feb 13, 2023 · 0 comments
Open

Use alterF machinery? #14

treeowl opened this issue Feb 13, 2023 · 0 comments

Comments

@treeowl
Copy link

treeowl commented Feb 13, 2023

alterF in containers has an internal lookup function that looks up a key in a Map. If the key is present, then it returns not only the associated value but also a record of where the key was found. If the key is absent, it returns a record of where the key would be inserted. I don't think information about missing keys is likely all that useful for this package. However, for maps with static key sets, it could be interesting to have one or more additional types.

data Location ph = Location !{- Whatever exactly Data.Map uses; I forget -}
data LocatedKey ph k = LocatedKey {-# UNPACK #-} !(Location ph) !k

It's possible to write functions like

lookupLoc :: Ord k => k -> Map ph k a -> Maybe (LocatedKey ph k, a)
lookupLTLoc :: Ord k => k -> Map ph k a -> Maybe (LocatedKey ph k, a)
iixLoc :: Functor f => Location ph -> (k -> a -> f a) -> Map ph k a -> f (Map ph k a)
toLocatedList :: Map ph k a -> [(LocatedKey ph k, a)]
deletingLoc ::
            Location ph  -- ^ key location to remove
         -> Map ph k v -- ^ initial map
         -> (forall ph'. (Key ph' k -> Key ph k, Map ph' k v) -> t) -- ^ continuation
         -> t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant