packages feed

comonad-transformers 1.5.2.1 → 1.5.2.2

raw patch · 4 files changed

+327/−1 lines, 4 filesdep +containersPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependencies added: containers

API changes (from Hackage documentation)

+ Data.Lens.Common: (^!%=) :: Lens a b -> (b -> b) -> a -> a
+ Data.Lens.Common: (^!) :: a -> Lens a b -> b
+ Data.Lens.Common: (^!*=) :: Num b => Lens a b -> b -> a -> a
+ Data.Lens.Common: (^!+=) :: Num b => Lens a b -> b -> a -> a
+ Data.Lens.Common: (^!-=) :: Num b => Lens a b -> b -> a -> a
+ Data.Lens.Common: (^!/=) :: Fractional b => Lens a b -> b -> a -> a
+ Data.Lens.Common: (^!=) :: Lens a b -> b -> a -> a
+ Data.Lens.Common: (^$!) :: Lens a b -> a -> b
+ Data.Lens.Common: (^$) :: Lens a b -> a -> b
+ Data.Lens.Common: (^%%=) :: Functor f => Lens a b -> (b -> f b) -> a -> f a
+ Data.Lens.Common: (^%=) :: Lens a b -> (b -> b) -> a -> a
+ Data.Lens.Common: (^*=) :: Num b => Lens a b -> b -> a -> a
+ Data.Lens.Common: (^+=) :: Num b => Lens a b -> b -> a -> a
+ Data.Lens.Common: (^-=) :: Num b => Lens a b -> b -> a -> a
+ Data.Lens.Common: (^.) :: a -> Lens a b -> b
+ Data.Lens.Common: (^/=) :: Fractional b => Lens a b -> b -> a -> a
+ Data.Lens.Common: (^=) :: Lens a b -> b -> a -> a
+ Data.Lens.Common: Lens :: (a -> Store b a) -> Lens a b
+ Data.Lens.Common: fstLens :: Lens (a, b) a
+ Data.Lens.Common: instance Category Lens
+ Data.Lens.Common: instance Semigroupoid Lens
+ Data.Lens.Common: intMapLens :: Int -> Lens (IntMap v) (Maybe v)
+ Data.Lens.Common: intSetLens :: Int -> Lens IntSet Bool
+ Data.Lens.Common: iso :: (a -> b) -> (b -> a) -> Lens a b
+ Data.Lens.Common: lens :: (a -> b) -> (b -> a -> a) -> Lens a b
+ Data.Lens.Common: mapLens :: Ord k => k -> Lens (Map k v) (Maybe v)
+ Data.Lens.Common: newtype Lens a b
+ Data.Lens.Common: runLens :: Lens a b -> a -> Store b a
+ Data.Lens.Common: setLens :: Ord k => k -> Lens (Set k) Bool
+ Data.Lens.Common: sndLens :: Lens (a, b) b
+ Data.Lens.Lazy: (!%%=) :: Monad m => Lens a b -> (b -> (c, b)) -> StateT a m c
+ Data.Lens.Lazy: (!%=) :: Monad m => Lens a b -> (b -> b) -> StateT a m b
+ Data.Lens.Lazy: (!&&=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool
+ Data.Lens.Lazy: (!*=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (!+=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (!-=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (!/=) :: (Monad m, Fractional b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (!=) :: Monad m => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (!||=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool
+ Data.Lens.Lazy: (%%=) :: Monad m => Lens a b -> (b -> (c, b)) -> StateT a m c
+ Data.Lens.Lazy: (%=) :: Monad m => Lens a b -> (b -> b) -> StateT a m b
+ Data.Lens.Lazy: (&&=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool
+ Data.Lens.Lazy: (*=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (+=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (-=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (//=) :: (Monad m, Fractional b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: (||=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool
+ Data.Lens.Lazy: (~=) :: Monad m => Lens a b -> b -> StateT a m b
+ Data.Lens.Lazy: access :: Monad m => Lens a b -> StateT a m b
+ Data.Lens.Lazy: focus :: Monad m => Lens a b -> StateT b m c -> StateT a m c
+ Data.Lens.Strict: (!%%=) :: Monad m => Lens a b -> (b -> (c, b)) -> StateT a m c
+ Data.Lens.Strict: (!%=) :: Monad m => Lens a b -> (b -> b) -> StateT a m b
+ Data.Lens.Strict: (!&&=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool
+ Data.Lens.Strict: (!*=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (!+=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (!-=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (!/=) :: (Monad m, Fractional b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (!=) :: Monad m => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (!||=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool
+ Data.Lens.Strict: (%%=) :: Monad m => Lens a b -> (b -> (c, b)) -> StateT a m c
+ Data.Lens.Strict: (%=) :: Monad m => Lens a b -> (b -> b) -> StateT a m b
+ Data.Lens.Strict: (&&=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool
+ Data.Lens.Strict: (*=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (+=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (-=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (//=) :: (Monad m, Fractional b) => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: (||=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool
+ Data.Lens.Strict: (~=) :: Monad m => Lens a b -> b -> StateT a m b
+ Data.Lens.Strict: access :: Monad m => Lens a b -> StateT a m b
+ Data.Lens.Strict: focus :: Monad m => Lens a b -> StateT b m c -> StateT a m c

Files

+ Data/Lens/Common.hs view
@@ -0,0 +1,140 @@+module Data.Lens.Common+  ( Lens(..)+  -- * Lens construction+  , lens -- build a lens from a getter and setter+  , iso  -- build a lens from an isomorphism+  -- * Functional API+  , (^$),  (^$!)   -- getter -- :: Lens a b -> a -> b+  , (^.),  (^!)    -- getter -- :: a -> Lens a b -> b+  , (^=),  (^!=)   -- setter -- :: Lens a b -> b -> (a -> a)+  , (^%=), (^!%=)  -- modify -- :: Lens a b -> (b -> b) -> (a -> a) +  , (^%%=)         -- modify -- :: Functor f => Lens a b -> (b -> f b) -> a -> f a+  -- * Pseudo-imperatives+  , (^+=), (^!+=) -- addition+  , (^-=), (^!-=) -- subtraction+  , (^*=), (^!*=) -- multiplication+  , (^/=), (^!/=) -- division+  -- * Stock lenses+  , fstLens+  , sndLens+  , mapLens+  , intMapLens+  , setLens+  , intSetLens+  ) where++import Control.Applicative+import Control.Comonad.Trans.Store+import Control.Category+import Data.Functor.Identity+import Data.Functor.Apply+import Data.Semigroupoid+import Prelude hiding ((.), id)+import Data.IntMap (IntMap)+import qualified Data.Map as Map+import Data.Set (Set)+import qualified Data.IntMap as IntMap+import Data.Map (Map)+import qualified Data.Set as Set+import Data.IntSet (IntSet)+import qualified Data.IntSet as IntSet++newtype Lens a b = Lens { runLens :: a -> Store b a }++instance Semigroupoid Lens where+  Lens f `o` Lens g = Lens $ \a -> case g a of+    StoreT wba b -> case f b of+      StoreT wcb c -> StoreT ((.) <$> wba <.> wcb) c++instance Category Lens where+  id = Lens $ StoreT (pure id)+  Lens f . Lens g = Lens $ \a -> case g a of+    StoreT wba b -> case f b of +      StoreT wcb c -> StoreT ((.) <$> wba <*> wcb) c++-- * Lens construction++-- | build a lens out of a getter and setter+lens :: (a -> b) -> (b -> a -> a) -> Lens a b+lens get set = Lens $ \a -> store (\b -> set b a) (get a)++-- | build a lens out of an isomorphism+iso :: (a -> b) -> (b -> a) -> Lens a b+iso f g = Lens (store g . f)++infixr 0 ^$, ^$!++-- | functional getter+(^$), (^$!)  :: Lens a b -> a -> b+Lens f ^$ a = pos (f a)+Lens f ^$! a = pos (f $! a)++infixr 9 ^., ^!+-- | functional getter, which acts like a field accessor+(^.), (^!) :: a -> Lens a b -> b+a ^. Lens f = pos (f a)+a ^! Lens f = pos (f $! a)++infixr 4 ^=, ^!=+-- | functional setter+(^=), (^!=) :: Lens a b -> b -> a -> a+Lens f ^= b = peek b . f+Lens f ^!= b = \a -> case f a of+  StoreT (Identity g) _ -> g $! b++infixr 4 ^%=, ^!%=+-- | functional modify+(^%=), (^!%=) :: Lens a b -> (b -> b) -> a -> a+Lens f ^%= g = peeks g . f+Lens f ^!%= g = \a -> case f a of+  StoreT (Identity h) b -> h $! g b++infixr 4 ^%%=+-- | functorial modify+(^%%=) :: Functor f => Lens a b -> (b -> f b) -> a -> f a+Lens f ^%%= g = \a -> case f a of+  StoreT (Identity h) b -> h <$> g b++infixr 4 ^+=, ^!+=, ^-=, ^!-=, ^*=, ^!*=+(^+=), (^!+=), (^-=), (^!-=), (^*=), (^!*=) :: Num b => Lens a b -> b -> a -> a+l ^+= n = l ^%= (+ n)+l ^-= n = l ^%= subtract n+l ^*= n = l ^%= (* n)+l ^!+= n = l ^!%= (+ n)+l ^!-= n = l ^!%= subtract n+l ^!*= n = l ^!%= (* n)++infixr 4 ^/=, ^!/=+(^/=), (^!/=) :: Fractional b => Lens a b -> b -> a -> a+l ^/= r = l ^%= (/ r)+l ^!/= r = l ^!%= (/ r)++-- * Stock lenses++fstLens :: Lens (a,b) a+fstLens = Lens $ \(a,b) -> store (\ a' -> (a', b)) a++sndLens :: Lens (a,b) b+sndLens = Lens $ \(a,b) -> store (\ b' -> (a, b')) b++mapLens :: Ord k => k -> Lens (Map k v) (Maybe v)+mapLens k = Lens $ \m -> store (\mv -> case mv of+    Nothing -> Map.delete k m+    Just v' -> Map.insert k v' m+  ) (Map.lookup k m)++intMapLens :: Int -> Lens (IntMap v) (Maybe v)+intMapLens k = Lens $ \m -> store (\mv -> case mv of+    Nothing -> IntMap.delete k m+    Just v' -> IntMap.insert k v' m+  ) (IntMap.lookup k m)++setLens :: Ord k => k -> Lens (Set k) Bool+setLens k = Lens $ \m -> store (\mv ->+    if mv then Set.delete k m else Set.insert k m+  ) (Set.member k m)+    +intSetLens :: Int -> Lens IntSet Bool+intSetLens k = Lens $ \m -> store (\mv -> +    if mv then IntSet.delete k m else IntSet.insert k m+  ) (IntSet.member k m)
+ Data/Lens/Lazy.hs view
@@ -0,0 +1,90 @@+module Data.Lens.Lazy+  ( module Data.Lens.Common+  -- * State API+  , access         -- getter -- :: Monad m => Lens a b -> StateT a m b+  , (~=), (!=)     -- setter -- :: Monad m => Lens a b -> b -> StateT a m b+  , (%=), (!%=)    -- modify -- :: Monad m => Lens a b -> (b -> b) -> StateT a m b+  , (%%=), (!%%=)  -- modify -- :: Monad m => Lens a b -> (b -> (c, b)) -> StateT a m c+  , (+=), (!+=)    -- modify -- :: (Monad m, Num b) => Lens a b -> b -> StateT a m b+  , (-=), (!-=)    -- modify -- :: (Monad m, Num b) => Lens a b -> b -> StateT a m b+  , (*=), (!*=)    -- modify -- :: (Monad m, Num b) => Lens a b -> b -> StateT a m b+  , (//=), (!/=)   -- modify -- :: (Monad m, Fractional b) => Lens a b -> b -> StateT a m b+  , (&&=), (!&&=)  -- modify -- :: Monad m => Lens a Bool -> Bool -> StateT a m Bool+  , (||=), (!||=)  -- modify -- :: Monad m => Lens a Bool -> Bool -> StateT a m Bool+  , focus          -- modify -- :: Monad m => Lens a b -> StateT m b c -> StateT m a c+  ) where++import Control.Comonad.Trans.Store+import Control.Monad.Trans.State+import Control.Monad (liftM)+import Data.Functor.Identity+import Data.Lens.Common++-- * State actions++-- | get the value of a lens into state+access :: Monad m => Lens a b -> StateT a m b+access (Lens f) = gets (pos . f)+{-# INLINE access #-}++focus :: Monad m => Lens a b -> StateT b m c -> StateT a m c+focus (Lens f) (StateT g) = StateT $ \a -> case f a of+  StoreT (Identity h) b -> liftM (\(c, b') -> (c, h b')) (g b)++infixr 4 ~=, !=++-- | set a value using a lens into state+(~=), (!=) :: Monad m => Lens a b -> b -> StateT a m b+Lens f ~= b = StateT $ \a -> let c = peek b (f a) in +    return (b, c)+Lens f != b = StateT $ \a -> case f a of+  StoreT (Identity h) _ -> let c = h $! b in+    return (b, c)++infixr 4 %=, !%=+    +-- | infix modification a value through a lens into state+(%=), (!%=) :: Monad m => Lens a b -> (b -> b) -> StateT a m b+Lens f %= g = StateT $ \a -> case f a of +  StoreT (Identity h) b -> let b' = g b in+    return (b', h b')+Lens f !%= g = StateT $ \a -> case f a of+  StoreT (Identity h) b -> let b' = g b in+    b' `seq` return (b', h b')++infixr 4 %%=, !%%=++-- | infix modification of a value through a lens into state+-- with a supplemental response+(%%=), (!%%=) :: Monad m => Lens a b -> (b -> (c, b)) -> StateT a m c+Lens f %%= g = StateT $ \a -> case f a of+  StoreT (Identity h) b -> case g b of+    (c, b') -> return (c, h b')+Lens f !%%= g = StateT $ \a -> case f a of+  StoreT (Identity h) b -> case g b of+    (c, b') -> return (c, h $! b')++infixr 4 +=, !+=, -=, !-=, *=, !*=++(+=), (!+=), (-=), (!-=), (*=), (!*=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b+f += b = f %= (+ b)+f -= b = f %= subtract b+f *= b = f %= (* b)+f !+= b = f !%= (+ b)+f !-= b = f !%= subtract b+f !*= b = f !%= (* b)++infixr 4 //=, !/=++(//=), (!/=) :: (Monad m, Fractional b) => Lens a b -> b -> StateT a m b+f //= b = f %= (/ b)+f !/= b = f !%= (/ b)++infixr 4 &&=, !&&=, ||=, !||=++(&&=), (||=), (!&&=), (!||=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool+f &&= b = f %= (&& b)+f ||= b = f %= (|| b)+f !&&= b = f !%= (&& b)+f !||= b = f !%= (|| b)+
+ Data/Lens/Strict.hs view
@@ -0,0 +1,90 @@+module Data.Lens.Strict+  ( module Data.Lens.Common+  -- * State API+  , access         -- getter -- :: Monad m => Lens a b -> StateT a m b+  , (~=), (!=)     -- setter -- :: Monad m => Lens a b -> b -> StateT a m b+  , (%=), (!%=)    -- modify -- :: Monad m => Lens a b -> (b -> b) -> StateT a m b+  , (%%=), (!%%=)  -- modify -- :: Monad m => Lens a b -> (b -> (c, b)) -> StateT a m c+  , (+=), (!+=)    -- modify -- :: (Monad m, Num b) => Lens a b -> b -> StateT a m b+  , (-=), (!-=)    -- modify -- :: (Monad m, Num b) => Lens a b -> b -> StateT a m b+  , (*=), (!*=)    -- modify -- :: (Monad m, Num b) => Lens a b -> b -> StateT a m b+  , (//=), (!/=)   -- modify -- :: (Monad m, Fractional b) => Lens a b -> b -> StateT a m b+  , (&&=), (!&&=)  -- modify -- :: Monad m => Lens a Bool -> Bool -> StateT a m Bool+  , (||=), (!||=)  -- modify -- :: Monad m => Lens a Bool -> Bool -> StateT a m Bool+  , focus          -- modify -- :: Monad m => Lens a b -> StateT m b c -> StateT m a c+  ) where++import Control.Comonad.Trans.Store+import Control.Monad.Trans.State.Strict+import Control.Monad (liftM)+import Data.Functor.Identity+import Data.Lens.Common++-- * State actions++-- | get the value of a lens into state+access :: Monad m => Lens a b -> StateT a m b+access (Lens f) = gets (pos . f)+{-# INLINE access #-}++focus :: Monad m => Lens a b -> StateT b m c -> StateT a m c+focus (Lens f) (StateT g) = StateT $ \a -> case f a of+  StoreT (Identity h) b -> liftM (\(c, b') -> (c, h b')) (g b)++infixr 4 ~=, !=++-- | set a value using a lens into state+(~=), (!=) :: Monad m => Lens a b -> b -> StateT a m b+Lens f ~= b = StateT $ \a -> let c = peek b (f a) in +    return (b, c)+Lens f != b = StateT $ \a -> case f a of+  StoreT (Identity h) _ -> let c = h $! b in+    return (b, c)++infixr 4 %=, !%=+    +-- | infix modification a value through a lens into state+(%=), (!%=) :: Monad m => Lens a b -> (b -> b) -> StateT a m b+Lens f %= g = StateT $ \a -> case f a of +  StoreT (Identity h) b -> let b' = g b in+    return (b', h b')+Lens f !%= g = StateT $ \a -> case f a of+  StoreT (Identity h) b -> let b' = g b in+    b' `seq` return (b', h b')++infixr 4 %%=, !%%=++-- | infix modification of a value through a lens into state+-- with a supplemental response+(%%=), (!%%=) :: Monad m => Lens a b -> (b -> (c, b)) -> StateT a m c+Lens f %%= g = StateT $ \a -> case f a of+  StoreT (Identity h) b -> case g b of+    (c, b') -> return (c, h b')+Lens f !%%= g = StateT $ \a -> case f a of+  StoreT (Identity h) b -> case g b of+    (c, b') -> return (c, h $! b')++infixr 4 +=, !+=, -=, !-=, *=, !*=++(+=), (!+=), (-=), (!-=), (*=), (!*=) :: (Monad m, Num b) => Lens a b -> b -> StateT a m b+f += b = f %= (+ b)+f -= b = f %= subtract b+f *= b = f %= (* b)+f !+= b = f !%= (+ b)+f !-= b = f !%= subtract b+f !*= b = f !%= (* b)++infixr 4 //=, !/=++(//=), (!/=) :: (Monad m, Fractional b) => Lens a b -> b -> StateT a m b+f //= b = f %= (/ b)+f !/= b = f !%= (/ b)++infixr 4 &&=, !&&=, ||=, !||=++(&&=), (||=), (!&&=), (!||=) :: Monad m => Lens a Bool -> Bool -> StateT a m Bool+f &&= b = f %= (&& b)+f ||= b = f %= (|| b)+f !&&= b = f !%= (&& b)+f !||= b = f !%= (|| b)+
comonad-transformers.cabal view
@@ -1,6 +1,6 @@ name:          comonad-transformers category:      Control, Comonads-version:       1.5.2.1+version:       1.5.2.2 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE@@ -26,6 +26,7 @@   build-depends:      base >= 4 && < 4.4,     comonad >= 1.0.1 && < 1.1,+    containers >= 0.4 && < 0.5,     contravariant >= 0.1.2 && < 0.2,     distributive >= 0.1 && < 0.2,     semigroupoids >= 1.1.1 && < 1.2,@@ -56,7 +57,12 @@     Control.Comonad.Trans.Traced     Control.Comonad.Trans.Traced.Memo     Control.Comonad.Trans.Stream+     Data.Functor.Coproduct     Data.Functor.Composition++    Data.Lens.Common+    Data.Lens.Lazy+    Data.Lens.Strict    ghc-options:      -Wall