Proposal: add Int indexing functions to Data.Set

Gwern Branwen gwern0 at gmail.com
Fri Apr 29 20:53:43 CEST 2011


On Fri, Apr 29, 2011 at 12:08 AM, Luis Casillas <luis at casillas.org> wrote:
> updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a

I took a look at all my local repos (c.h.o, Patch-tag, misc repos, and
GitHub since I recently re-ran
http://www.gwern.net/haskell/Archiving%20GitHub.html ).

A grep* for updateAt (randomly picked one whose name looked like it'd
be fairly unique) turned up what seems to be very few actual uses of
updateAt, and mostly similarly named functions and various
implementations of updateAt.

The results are attached if anyone would like to see what actual uses
there are in the wild. If anyone wants to see the output for the other
functions, I can re-run the grep.

* find ~/bin/ -name "*.hs" -exec grep -l updateAt {} \; -exec grep
updateAt {} \; > ~/updateat.txt

-- 
gwern
http://www.gwern.net
-------------- next part --------------
bin/adaptive-containers/Data/Adaptive/Map.hs
            , updateAt
-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
updateAt :: (AdaptMap k a) => (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt f i t    = mapMap (error "Map.updateAt: index out of range") b t
                          LT -> balance kx x (updateAt f i l) r
                          GT -> balance kx x l (updateAt f (i-sizeL-1) r)
{-# INLINE updateAt #-}
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
deleteAt i m = updateAt (\_ _ -> Nothing) i m
bin/ghc/libraries/containers/Data/Map.hs
            , updateAt
-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt f i t = i `seq`
    Tip -> error "Map.updateAt: index out of range"
      LT -> balanceR kx x (updateAt f i l) r
      GT -> balanceL kx x l (updateAt f (i-sizeL-1) r)
{-# INLINABLE updateAt #-}
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
  = updateAt (\_ _ -> Nothing) i m
bin/ghc/libraries/containers/tests/map-properties.hs
             , testCase "updateAt" test_updateAt
test_updateAt :: Assertion
test_updateAt = do
    updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) @?= fromList [(3, "x"), (5, "a")]
    updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) @?= fromList [(3, "b"), (5, "x")]
    updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) @?= singleton 5 "a"
    updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) @?= singleton 3 "b"
--    updateAt (\_ _  -> Nothing)  7    (fromList [(5,"a"), (3,"b")]) @?= singleton 3 "b"
bin/ghc/libraries/containers/tests/intmap-properties.hs
--             , testCase "updateAt" test_updateAt
-- test_updateAt :: Assertion
-- test_updateAt = do
--     updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) @?= fromList [(3, "x"), (5, "a")]
--     updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) @?= fromList [(3, "b"), (5, "x")]
--     updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) @?= singleton 5 "a"
--     updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) @?= singleton 3 "b"
bin/ghc/libraries/containers/tests/datamap001.hs
              m' = updateAt f 1 m
bin/deech/hpodder/Commands/Download.hs
                       updateAttempt curtime $
updateAttempt curtime ep =
           updateAttempt curtime $ (newep {epstatus = Downloaded})
bin/gregwebs/haskell-sphinx-client/Text/Search/Sphinx.hs
-- updateAttributes,
bin/pepeiborra/narradar/src/Narradar/Constraints/Syntactic.hs
                        [ (p, updateAt p (const r') l \\ sigma, r \\ sigma)
                        [ (p, updateAt p (const r') l \\ sigma, r \\ sigma)
bin/pepeiborra/narradar/src/Narradar/Processor/GraphTransformation.hs
maps' f xx = [ updateAt i xx | i <- [0..length xx - 1]] where
  updateAt 0 (x:rest) = f x      : map return rest
  updateAt i (x:xx)   = return x : updateAt (i-1) xx
bin/pepeiborra/narradar/src/Narradar/Processor/PrologProblem.hs
              $ updateAnswer u_i ((updateAt [1] (mapRootSymbol (mapLabel (fmap (delete i))))))
    r'     = updateAt (init pos) (mapRootSymbol (mapLabel (fmap (delete i)))) r
                                  -- ((:[]) . updateAt (1 : init pos) (mapRootSymbol (mapLabel (fmap (delete (last pos))))))
                                  (\r -> case updateAt' (1 : init pos) (mapRootSymbol (mapLabel (fmap (delete (last pos))))) r of
            (updateAnswers (Set.singleton $ fromJust $ getUId u_i) ((:[]) . updateAt [1] (const out)))
                    p_rr1{inRule = left(updateAt p (const(applySubst sigma (l_in' ! p)))) (inRule p_rr1)}
bin/pepeiborra/trs/src/TRS/Term.hs
updateAt  :: (Traversable f, HashConsed f) =>  Position -> Term f -> (Term f -> Term f) -> Term f
updateAt [] t f = f t
updateAt (0:_) _ _ = error "updateAt: 0 is not a position!"
updateAt (i:ii) (In t) f = {-# SCC "updateAt" #-}
                            hIn$ fmap (\(j,st) -> if i==j then updateAt ii st f else st)
updateAt'  :: (Traversable f, HashConsed f, Monad m) =>
updateAt' pos x f = {-# SCC "updateAt'" #-}
                     maybe (fail "updateAt': invalid position") return
    go _      (0:_)  = fail "updateAt: 0 is not a position!"
bin/pepeiborra/trs/src/TRS/Context.hs
             , (u, t_i) <- updateAt' [i] t' (const $ hole 0) ]
bin/pepeiborra/trs/src/TRS/Confluence.hs
  let l1'    = updateAt (note l1_p) l1 (const r2)
bin/pepeiborra/term/Data/Term.hs
     Position, positions, (!), (!*), (!?), updateAt, updateAt', updateAtM, occurrences,
updateAt  :: (Traversable f) =>  Position -> (Term f v -> Term f v) -> Term f v -> Term f v
updateAt (0:_)  _          _ = error "updateAt: 0 is not a position!"
updateAt []     f          t = f t
updateAt (i:ii) f (Impure t) = Impure (unsafeZipWithG g [1..] t)
                               where g j st = if i==j then updateAt ii f st else st
updateAt _      _          _ = error "updateAt: invalid position given"
updateAt'  :: (Traversable f, Monad m) =>
updateAt' pos f = updateAtM pos (return . f)
-- | Monadic version of @updateAt'@
updateAtM  :: (Traversable f, Monad m) =>
updateAtM pos f t = runStateT (go pos t) t where
 go (0:_)  _          = fail "updateAt: 0 is not a position!"
 go _      _          = fail "updateAt: invalid position given"
bin/pepeiborra/term/Data/Term/Annotated/Rewriting.hs
rewrite1p rr t p = liftM fst $ updateAtM p (rewriteTop rr) t
bin/pepeiborra/term/Data/Term/Annotated/Narrowing.hs
             , (u, t_i) <- updateAt' [i] (const mempty)(Free.fmap Right t) ]
bin/pepeiborra/term/Data/Term/Rewriting.hs
rewrite1p rr t p = liftM fst $ updateAtM p (rewriteTop rr) t
bin/pepeiborra/term/Data/Term/Annotated.hs
     Position, positions, (!), (!*), (!?), updateAt, updateAt', updateAtM, occurrences,
updateAt  :: (Traversable f, Measured a ann) =>  Position -> (Term ann f a -> Term ann f a) -> Term ann f a -> Term ann f a
updateAt (0:_)  _ = error "updateAt: 0 is not a position!"
updateAt []     f = f
updateAt (i:ii) f = evalFree err (\t -> impure (unsafeZipWithG g [1..] t))
         where g j st = if i==j then updateAt ii f st else st
               err = error "updateAt: invalid position given"
updateAt'  :: (Traversable f, Measured a ann, Monad m) =>
updateAt' pos f = updateAtM pos (return . f)
-- | Monadic version of @updateAt'@
updateAtM  :: (Traversable f, Measured a ann, Monad m) =>
updateAtM pos f t = runStateT (go pos t) t where
 go (0:_)  _ = fail "updateAt: 0 is not a position!"
  where fai    = fail "updateAt: invalid position given"
bin/pepeiborra/term/Data/Term/Narrowing.hs
             , (u, t_i) <- updateAt' [i] (const mempty)(fmap Right t) ]
bin/jeremyong/Yaiba/Yaiba/Map.hs
            , updateAt
-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt _ _ Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> balance kx x (updateAt f i l) r
      GT -> balance kx x l (updateAt f (i-sizeL-1) r)
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
  = updateAt (\_ _ -> Nothing) i m
bin/hlist/Data/HList/Record.hs
    hTPupdateAtLabel,
hTPupdateAtLabel :: (HasField l t a,HUpdateAtHNat n (LVPair l a) t l',HFind l ls n,RecordLabels t ls) =>
hTPupdateAtLabel l v r = hUpdateAtLabel l v r
> hTPupdateAtLabel l v r = hUpdateAtLabel l v r `asTypeOf` r
             ur' = hTPupdateAtLabel (undefined::l2) v2 ur
bin/hlist/Data/HList/GhcSyntax.hs
f@(LVPair v) .<. r = hTPupdateAtLabel (labelLVPair f) v r
bin/lhc/lib/containers-0.2.0.1/Data/Map.hs
            , updateAt
-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt _ _ Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> balance kx x (updateAt f i l) r
      GT -> balance kx x l (updateAt f (i-sizeL-1) r)
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
  = updateAt (\_ _ -> Nothing) i m
bin/blobs/lib/DData/Map.hs
            , updateAt
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt f i Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> updateAt f i l
      GT -> updateAt f (i-sizeL-1) r
-- | /O(log n)/. Delete the element at /index/. Defined as (@deleteAt i map = updateAt (\k x -> Nothing) i map@).
  = updateAt (\k x -> Nothing) i map
bin/blobs/_darcs/pristine/lib/DData/Map.hs
            , updateAt
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt f i Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> updateAt f i l
      GT -> updateAt f (i-sizeL-1) r
-- | /O(log n)/. Delete the element at /index/. Defined as (@deleteAt i map = updateAt (\k x -> Nothing) i map@).
  = updateAt (\k x -> Nothing) i map
bin/kaoskorobase/mescaline/resources/hugs/packages/base/Data/Map.hs
            , updateAt
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt f i Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> updateAt f i l
      GT -> updateAt f (i-sizeL-1) r
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
  = updateAt (\k x -> Nothing) i map
bin/dmpots/lhc/lib/containers-0.2.0.1/Data/Map.hs
            , updateAt
-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt _ _ Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> balance kx x (updateAt f i l) r
      GT -> balance kx x l (updateAt f (i-sizeL-1) r)
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
  = updateAt (\_ _ -> Nothing) i m
bin/dmpots/fibon-benchmarks/Hackage/Gf/src/runtime/haskell/PGF/Parse.hs
                                     Just id -> (Active j (ppos+1) funid seqid (updateAt d id args) key0) : items
                                                                !acc' = fn toks (Active j (ppos+1) funid seqid (updateAt d fid' args) key0) acc
                                                            in (:) (Active j' (ppos+1) funid seqid (updateAt d fid args) keyc)) items set
updateAt :: Int -> a -> [a] -> [a]
updateAt nr x xs = [if i == nr then x else y | (i,y) <- zip [0..] xs]
bin/kazu-yamamoto/bst/Data/SMap/Internal.hs
-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt _ _ Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> balance kx x (updateAt f i l) r
      GT -> balance kx x l (updateAt f (i-sizeL-1) r)
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
  = updateAt (\_ _ -> Nothing) i m
bin/kazu-yamamoto/bst/Data/SMap.hs
            , updateAt
bin/kazu-yamamoto/bst/test/Test.hs
             , testCase "updateAt" test_updateAt
test_updateAt :: Assertion
test_updateAt = do
    updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) @?= fromList [(3, "x"), (5, "a")]
    updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) @?= fromList [(3, "b"), (5, "x")]
    updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) @?= singleton 5 "a"
    updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) @?= singleton 3 "b"
bin/jgoerzen/hpodder/Commands/Download.hs
                       updateAttempt curtime $
updateAttempt curtime ep =
           updateAttempt curtime $ (newep {epstatus = Downloaded})
bin/gf/src/PGF/Parsing/FCFG/Incremental.hs
                                      Just id -> (Active j (ppos+1) funid seqid (updateAt d id args) key0) : items
                                                                 !acc' = fn toks (Active j (ppos+1) funid seqid (updateAt d fid' args) key0) acc
                                                            in (:) (Active j' (ppos+1) funid seqid (updateAt d fid args) keyc)) items set
updateAt :: Int -> a -> [a] -> [a]
updateAt nr x xs = [if i == nr then x else y | (i,y) <- zip [0..] xs]
bin/gf/src/runtime/haskell/PGF/Parse.hs
                                     Just id -> (Active j (ppos+1) funid seqid (updateAt d (PArg hypos id) args) key0) : items
                           (toks:_) -> let !acc' = ftok_ toks (Active j (ppos+1) funid seqid (updateAt d (PArg hypos fid') args) key0) acc
                                                            !acc' = ftok_ toks (Active j (ppos+1) funid seqid (updateAt d (PArg hypos fid') args) key0) acc
                           (toks:_) -> let !acc' = ftok_ toks (Active j (ppos+1) funid seqid (updateAt d (PArg (updateAt r (fid',fid2) hypos) fid0) args) key0) acc
                                                        !acc' = ftok_ toks (Active j (ppos+1) funid seqid (updateAt d (PArg (updateAt r (fid',fid2) hypos) fid0) args) key0) acc
                                                                in (:) (Active j' (ppos+1) funid seqid (updateAt d (PArg hypos fid) args) keyc)) items set
updateAt :: Int -> a -> [a] -> [a]
updateAt nr x xs = [if i == nr then x else y | (i,y) <- zip [0..] xs]
bin/pirapira/bst/Data/SMap/Internal.hs
-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt _ _ Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> balance kx x (updateAt f i l) r
      GT -> balance kx x l (updateAt f (i-sizeL-1) r)
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
  = updateAt (\_ _ -> Nothing) i m
bin/pirapira/bst/Data/SMap.hs
            , updateAt
bin/pirapira/bst/test/Test.hs
             , testCase "updateAt" test_updateAt
test_updateAt :: Assertion
test_updateAt = do
    updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) @?= fromList [(3, "x"), (5, "a")]
    updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) @?= fromList [(3, "b"), (5, "x")]
    updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) @?= singleton 5 "a"
    updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) @?= singleton 3 "b"
bin/mokus0/dependent-map/src/Data/Dependent/Map.hs
    , updateAt
updateAt :: (forall v. k v -> v -> Maybe v) -> Int -> DMap k -> DMap k
updateAt f i0 t = i0 `seq` go i0 t
    go _ Tip  = error "Map.updateAt: index out of range"
  = updateAt (\_ _ -> Nothing) i m
bin/haskore/src/Haskore/General/Map.hs
        lookupIndex, findIndex, elemAt, updateAt, deleteAt,
    elemAt, updateAt, deleteAt,
bin/thoughtpolice/testsuite/tests/libraries/Data/reference/Map.hs
-- TODO updateAt
bin/altaic/testsuite/tests/libraries/Data/reference/Map.hs
-- TODO updateAt
bin/pure/software/haskell/libraries/Data/G/Experiment.hs
           where r' = Record pir (updateAtLabel pul l r v)
updateAtLabel :: UpdateAtLabel l r v -> l -> r -> v  -> r
updateAtLabel UpdateAtLabelNil _ r _ = r
updateAtLabel UpdateAtLabelCons1 _ (Cons (l,_) r) v = Cons (l,v) r
updateAtLabel (UpdateAtLabelCons2 pte pul) l' (Cons (l,v') r) v = Cons (l,v') (updateAtLabel pul l' r v)
bin/pure/software/haskell/libraries/Data/HListExtras.hs
   = updateWith (hTPupdateAtLabel l v r) s
bin/pure/software/haskell/contrib/OOHaskell/HList/Record.hs
hTPupdateAtLabel l (v::v) r = hUpdateAtLabel l v r
bin/pure/software/haskell/contrib/OOHaskell/HList/GhcSyntax.hs
(l,v) .<. r = hTPupdateAtLabel l v r
bin/pure/software/haskell/contrib/HList/Record.hs
hTPupdateAtLabel l (v::v) r = hUpdateAtLabel l v r
bin/pure/software/haskell/contrib/HList/GhcSyntax.hs
(l,v) .<. r = hTPupdateAtLabel l v r
bin/nullset1/hpodder/Commands/Download.hs
                       updateAttempt curtime $
updateAttempt curtime ep =
           updateAttempt curtime $ (newep {epstatus = Downloaded})
bin/yhc/src/packages/yhc-base-1.0/Data/Map.hs
            , updateAt
updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
updateAt f i Tip  = error "Map.updateAt: index out of range"
updateAt f i (Bin sx kx x l r)
      LT -> updateAt f i l
      GT -> updateAt f (i-sizeL-1) r
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).
  = updateAt (\k x -> Nothing) i map
bin/mchakravarty/testsuite/tests/libraries/Data/reference/Map.hs
-- TODO updateAt
bin/lowasser/TrieMap/Data/TrieMap.hs
	updateAt,
-- > updateAt (\ _ _ -> Just "x") 0    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")]
-- > updateAt (\ _ _ -> Just "x") 1    (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")]
-- > updateAt (\ _ _ -> Just "x") 2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  0    (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
-- > updateAt (\_ _  -> Nothing)  1    (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
-- > updateAt (\_ _  -> Nothing)  2    (fromList [(5,"a"), (3,"b")])    Error: index out of range
-- > updateAt (\_ _  -> Nothing)  (-1) (fromList [(5,"a"), (3,"b")])    Error: index out of range
{-# INLINEABLE updateAt #-}
updateAt :: TKey k => (k -> a -> Maybe a) -> Int -> TMap k a -> TMap k a
updateAt f i m = case index i m of
-- Defined as (@'deleteAt' i map = 'updateAt' (\k x -> 'Nothing') i map@).


More information about the Libraries mailing list