HMap 1.1.7 → 1.1.8
raw patch · 3 files changed
+21/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog +2/−0
- Data/HKeyPrivate.hs +18/−0
- HMap.cabal +1/−1
ChangeLog view
@@ -1,3 +1,5 @@+1.1.8 : Added an Applicative instance for KeyT that is more non-strict than using the monad instance.+ 1.1.7: Fixed example in docs. 1.1.6: Better memory performance: An entry into an HMap does not keep the value alive if the key is not alive. After all, if the key is dead, then there is no way to retrieve the value! Also added IO operation purge to remove dead elements.
Data/HKeyPrivate.hs view
@@ -25,6 +25,7 @@ import Data.Unique import System.IO.Unsafe import Control.Monad+import Control.Applicative import Control.Monad.Identity import Control.Monad.Trans import Data.Hashable@@ -90,6 +91,7 @@ interpret :: Bind f a v -> (a -> v) -> TermM f a -> v interpret bind ret = int where int (Return a) = ret a+ int (Prim x) = bind x return int (Bind (Prim x) f) = bind x f int (Bind (Return x) f) = int (f x) int (Bind (Bind p q) r) = int (Bind p (\x -> Bind (q x) r))@@ -99,12 +101,28 @@ -- Keys cannot escape the monad, analogous to the ST Monad. -- Can be used instead of the 'withKey' function if you -- need an statically unknown number of keys.+-- +-- The applicative instance is more non-strict than +-- the standard 'ap':+--+-- let hang = getKey >> hang+-- in snd $ runIdentity $ runKeyT $ pure (,) <*> hang <*> (getKey >> return 2)+-- does not hang, but with 'ap' it does.+ type KeyM s a = KeyT s Identity a newtype KeyT s m a = KeyT { getKT :: TermM (GD s m) a } +instance Functor (KeyT s m) where+ fmap f m = m >>= return . f ++instance Monad m => Applicative (KeyT s m) where+ pure = return+ f <*> x = do fv <- keyTSplit f; xv <- keyTSplit x; lift (ap fv xv)+ instance Monad (KeyT s m) where return = KeyT . Return c >>= f = KeyT $ getKT c >>= getKT . f+ -- | Obtain a key in the key monad
HMap.cabal view
@@ -1,5 +1,5 @@ Name: HMap-Version: 1.1.7+Version: 1.1.8 Synopsis: Fast heterogeneous maps and unconstrained typeable like functionality. Description: Fast heterogeneous maps based on Hashmaps and type-able like functionality for type that are not typeable. License: BSD3