observable-sharing 0.2.1.2 → 0.2.2.0
raw patch · 2 files changed
+36/−17 lines, 2 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.Ref: [deref] :: Ref a -> a
- Data.Ref: [label] :: Ref a -> StableName a
- Data.Ref: instance GHC.Classes.Eq (Data.Ref.Ref a)
- Data.Ref: instance GHC.Show.Show a => GHC.Show.Show (Data.Ref.Ref a)
- Data.Ref.Map: debug :: Map f -> (forall a. f a -> String) -> IO ()
+ Data.Ref: deref :: Ref a -> a
+ Data.Ref: instance Eq (Ref a)
+ Data.Ref: instance Show a => Show (Ref a)
+ Data.Ref: label :: Ref a -> StableName a
+ Data.Ref.Map: (!) :: Map f -> Name a -> f a
+ Data.Ref.Map: Hide :: f a -> HideType f
+ Data.Ref.Map: data HideType f
+ Data.Ref.Map: dump :: Map f -> [[(HideType Name, HideType f)]]
+ Data.Ref.Map: hmap :: (f a -> h a) -> Map f -> Map h
- Data.Ref.Map: adjust :: (f a -> f b) -> Ref a -> Map f -> Map f
+ Data.Ref.Map: adjust :: (f a -> f b) -> Name a -> Map f -> Map f
- Data.Ref.Map: delete :: Ref a -> Map f -> Map f
+ Data.Ref.Map: delete :: Name a -> Map f -> Map f
Files
- observable-sharing.cabal +2/−2
- src/Data/Ref/Map.hs +34/−15
observable-sharing.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: observable-sharing-version: 0.2.1.2+version: 0.2.2.0 synopsis: Simple observable sharing -- description: license: BSD3@@ -28,7 +28,7 @@ Data.Ref.Map -- other-modules: -- other-extensions: - build-depends: base >=4.8 && <4.9,+ build-depends: base >=4 && <5, containers hs-source-dirs: .,src default-language: Haskell2010
src/Data/Ref/Map.hs view
@@ -8,23 +8,29 @@ , null , size , member+ , (!) , lookup , insert , delete , adjust+ , hmap , union , difference , intersection- , debug+ -- eehh...+ , HideType(..)+ , dump ) where +import Control.Applicative ((<$>)) import Data.Ref import Data.List (find, deleteBy) import Data.Function (on)-import Unsafe.Coerce -- lets use all the unsafe operations!++import Unsafe.Coerce import System.Mem.StableName -import Data.IntMap (IntMap)+import Data.IntMap (IntMap) import qualified Data.IntMap as M import Prelude hiding (null, lookup, map, filter)@@ -72,6 +78,10 @@ member :: Name a -> Map f -> Bool member n (Map m) = M.member (hashStableName n) m +-- | Unsafe lookup+(!) :: Map f -> Name a -> f a+(!) m name = maybe (error "Data.Ref.Map.(!)") id (lookup name m)+ -- | Finds the value associated with the name, or 'Nothing' if the name has no -- value associated to it. lookup :: Name a -> Map f -> Maybe (f a)@@ -87,21 +97,31 @@ insert (Ref n _) v (Map m) = Map $ M.insertWith (++) (hashStableName n) [(Hide n, Hide v)] m -- | Removes the associated value of a reference, if any is present in the map.-delete :: Ref a -> Map f -> Map f-delete (Ref n _) map@(Map m) = Map $ M.update del (hashStableName n) m+delete :: Name a -> Map f -> Map f+delete n map@(Map m) = Map $ M.update del (hashStableName n) m where del (_:[]) = Nothing del xs = Just $ deleteBy apa (Hide n, undefined) xs apa (Hide x, _) (Hide y, _) = eqStableName x y -- | Updates the associated value of a reference, if any is present in the map.-adjust :: (f a -> f b) -> Ref a -> Map f -> Map f-adjust f (Ref n _) (Map m) = Map $ M.adjust fun (hashStableName n) m+adjust :: (f a -> f b) -> Name a -> Map f -> Map f+adjust f n (Map m) = Map $ M.adjust fun (hashStableName n) m where- fun xs = fmap (\p@(Hide x, _) -> if eqStableName x n then apa p else p) xs- apa (n, Hide v) = (n, Hide $ f $ unsafeCoerce v)+ fun xs = flip fmap xs $ \pair@(Hide x, Hide v) ->+ if eqStableName x n+ then (Hide x, Hide $ f $ unsafeCoerce v)+ else pair --------------------------------------------------------------------------------+-- ** Traversal++hmap :: (f a -> h a) -> Map f -> Map h+hmap f (Map m) = Map $ M.map (fmap $ fmap h) m+ where+ h (Hide x) = Hide $ f $ unsafeCoerce x++-------------------------------------------------------------------------------- -- ** Combine -- | Union of two maps (left biased).@@ -117,12 +137,11 @@ intersection (Map m) (Map n) = Map $ M.intersection m n ----------------------------------------------------------------------------------- ** Debug+-- ** Debug - These are probably not safe -debug :: Map f -> (forall a. f a -> String) -> IO ()-debug (Map m) f = do- let es = flip fmap (M.elems m) $ fmap (\(Hide x, Hide y) -> (hashStableName x, f y))- putStrLn $ "*** Debug"- ++ "\n\t elems: " ++ show es+-- data Entry f = forall a. Entry a (f a)++dump :: Map f -> [[(HideType Name, HideType f)]]+dump (Map m) = M.elems m --------------------------------------------------------------------------------