observable-sharing 0.2.3 → 0.2.4
raw patch · 2 files changed
+12/−2 lines, 2 files
Files
- observable-sharing.cabal +1/−1
- src/Data/Ref/Map.hs +11/−1
observable-sharing.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: observable-sharing-version: 0.2.3+version: 0.2.4 synopsis: Simple observable sharing -- description: license: BSD3
src/Data/Ref/Map.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE GADTs, ScopedTypeVariables #-}+{-# LANGUAGE GADTs, ScopedTypeVariables, Rank2Types #-} module Data.Ref.Map ( Map@@ -14,6 +14,7 @@ , insert -- :: Ref a -> f a -> Map f -> Map f , delete -- :: Name a -> Map f -> Map f , adjust -- :: (f a -> f b) -> Name a -> Map f -> Map f+ , filter -- :: (f a -> Bool) -> Map f -> Map f , hmap -- :: (f a -> h a) -> Map f -> Map h , union , difference@@ -50,6 +51,8 @@ -- | A reference indexed map. -- Useful for associating info with a reference.+--+-- Note: this is generally unsound when `f` is a GADT! data Map f = Map (IntMap [(HideType Name, HideType f)]) --------------------------------------------------------------------------------@@ -115,6 +118,13 @@ open pair@(Hide x, Hide v) | x `eqStableName` n = (Hide x, Hide $ f $ unsafeCoerce v) | otherwise = pair++-- | Filters the map for values matching the predicate+filter :: (forall a. f a -> Bool) -> Map f -> Map f+filter f (Map m) = Map $ M.filter (unwrap f) m+ where+ unwrap :: (forall a. f a -> Bool) -> [(HideType Name, HideType f)] -> Bool+ unwrap f = and . fmap (\(_, Hide a) -> f a) -------------------------------------------------------------------------------- -- ** Traversal