packages feed

observable-sharing 0.1.1.0 → 0.2.0.0

raw patch · 3 files changed

+13/−13 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Ref: [refNr] :: Ref a -> Unique
+ Data.Ref: [label] :: Ref a -> StableName a
- Data.Ref: Ref :: Unique -> a -> Ref a
+ Data.Ref: Ref :: StableName a -> a -> Ref a

Files

observable-sharing.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                observable-sharing-version:             0.1.1.0+version:             0.2.0.0 synopsis:            Simple observable sharing -- description:          license:             BSD3
src/Data/Ref.hs view
@@ -1,6 +1,6 @@ module Data.Ref where -import Data.Unique+import System.Mem.StableName import System.IO.Unsafe import Control.Applicative @@ -8,16 +8,16 @@ -- * References -------------------------------------------------------------------------------- -data Ref a = Ref { refNr :: Unique , deref :: a }+data Ref a = Ref { label :: StableName a, deref :: a }  instance Eq (Ref a) where-  Ref u1 _ == Ref u2 _ = u1 == u2+  Ref s1 _ == Ref s2 _ = s1 == s2  instance Show a => Show (Ref a) where-  show (Ref u x) = "(Ref " ++ show (hashUnique u) ++ " " ++ show x ++ ")"+  show (Ref s x) = "(Ref " ++ show (hashStableName s) ++ " " ++ show x ++ ")"  ref :: a -> Ref a-ref x = unsafePerformIO $ flip Ref x <$> newUnique+ref x = unsafePerformIO $ flip Ref x <$> makeStableName x {-# NOINLINE ref #-}  --------------------------------------------------------------------------------
src/Data/Ref/Map.hs view
@@ -19,8 +19,8 @@   ) where  import Data.Ref-import Data.Unique import Unsafe.Coerce -- lets use all the unsafe operations!+import System.Mem.StableName (hashStableName)  import qualified Data.HashMap.Lazy as H @@ -49,7 +49,7 @@  -- | Construct a map with a single element. singleton :: Ref a -> f a -> Map f-singleton (Ref u _) v = Map $ H.singleton (hashUnique u) (Hide v)+singleton (Ref u _) v = Map $ H.singleton (hashStableName u) (Hide v)  -------------------------------------------------------------------------------- -- ** Basic interface@@ -64,25 +64,25 @@  -- | Returns 'True' if the reference is present in the map, 'False' otherwise. member :: Ref a -> Map f -> Bool-member (Ref u _) (Map m) = H.member (hashUnique u) m+member (Ref u _) (Map m) = H.member (hashStableName u) m  -- | Returns the value associated with the reference, or 'Nothing' if the reference -- has no value associated to it. lookup :: Ref a -> Map f -> Maybe (f a)-lookup (Ref u _) (Map m) = fmap unsafeCoerce $ H.lookup (hashUnique u) m+lookup (Ref u _) (Map m) = fmap unsafeCoerce $ H.lookup (hashStableName u) m  -- | Associates a reference with the specified value. If the map already contains -- a mapping for the reference, the old value is replaced. insert :: Ref a -> f a -> Map f -> Map f-insert (Ref u _) v (Map m) = Map $ H.insert (hashUnique u) (Hide v) m+insert (Ref u _) v (Map m) = Map $ H.insert (hashStableName u) (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 u _) (Map m) = Map $ H.delete (hashUnique u) m+delete (Ref u _) (Map m) = Map $ H.delete (hashStableName u) m  -- | 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 u _) (Map m) = Map $ H.adjust (\(Hide v) -> Hide $ f $ unsafeCoerce v) (hashUnique u) m+adjust f (Ref u _) (Map m) = Map $ H.adjust (\(Hide v) -> Hide $ f $ unsafeCoerce v) (hashStableName u) m  -------------------------------------------------------------------------------- -- ** Combine