lensref 0.1.0.5 → 0.2
raw patch · 9 files changed
+137/−46 lines, 9 filesdep +lensrefdep ~transformersPVP ok
version bump matches the API change (PVP)
Dependencies added: lensref
Dependency ranges changed: transformers
API changes (from Hackage documentation)
- Data.LensRef.Default: runRegister :: NewRef m => (forall a. m (m a, a -> m ())) -> Register m a -> m (a, m ())
- Data.LensRef.Default: type Register m = Reg (Wrap m)
- Data.LensRef.Fast: instance MonadRegisterRun (Register (Prog TP))
- Data.LensRef.Pure: instance MonadRegisterRun (Register (Prog TP))
- Data.LensRef.Test: mkTests :: (MonadRegisterRun m, MonadRefWriter m, EffectM m ~ Prog (AsocT m), Monad n) => (m () -> n ()) -> n ()
- Data.LensRef.Test: tests :: (MonadRegisterRun m, EffectM m ~ Prog (AsocT m), Monad n, MonadRegister (Modifier m)) => (forall a. (Eq a, Show a) => String -> m a -> Prog' (a, Prog' ()) -> n ()) -> n ()
- Data.LensRef.TestEnv: (==>) :: (Eq a, Show a, MonadRegisterRun m, EffectM m ~ Prog (AsocT m)) => Ref m a -> a -> m ()
- Data.LensRef.TestEnv: (==?) :: (Eq a, Show a, MonadRegisterRun m, EffectM m ~ Prog (AsocT m)) => a -> a -> m ()
- Data.LensRef.TestEnv: Any :: x -> Any
- Data.LensRef.TestEnv: Error' :: String -> Inst' ()
- Data.LensRef.TestEnv: Id :: Int -> Id
- Data.LensRef.TestEnv: Listen :: Port b -> (b -> Prog t ()) -> Inst t Id
- Data.LensRef.TestEnv: Listener :: Id -> Port a -> RegionStatusChange -> (a -> Prog m ()) -> Listener m
- Data.LensRef.TestEnv: Message :: String -> Inst t ()
- Data.LensRef.TestEnv: Message' :: String -> Inst' ()
- Data.LensRef.TestEnv: NewRef :: a -> Inst t (Morph (StateT a (Prog t)) (Prog t))
- Data.LensRef.TestEnv: Port :: Int -> Port a
- Data.LensRef.TestEnv: ReadI :: Inst t t
- Data.LensRef.TestEnv: ST :: [m] -> [Listener m] -> Int -> Seq Any -> ST m
- Data.LensRef.TestEnv: Send :: Port a -> a -> Inst' ()
- Data.LensRef.TestEnv: SetStatus :: Id -> RegionStatusChange -> Inst t ()
- Data.LensRef.TestEnv: WriteI :: t -> Inst t ()
- Data.LensRef.TestEnv: _idcounter :: ST m -> Int
- Data.LensRef.TestEnv: _listenerCallback :: Listener m -> a -> Prog m ()
- Data.LensRef.TestEnv: _listenerId :: Listener m -> Id
- Data.LensRef.TestEnv: _listenerPort :: Listener m -> Port a
- Data.LensRef.TestEnv: _listenerStatus :: Listener m -> RegionStatusChange
- Data.LensRef.TestEnv: _listeners :: ST m -> [Listener m]
- Data.LensRef.TestEnv: _postponed :: ST m -> [m]
- Data.LensRef.TestEnv: _vars :: ST m -> Seq Any
- Data.LensRef.TestEnv: class MonadRegister tm => MonadRegisterRun tm where type family AsocT tm :: *
- Data.LensRef.TestEnv: coeval_ :: (Prog m () -> m) -> Prog m a -> Prog' b -> StateT (ST m) Er (Maybe a, Prog' b)
- Data.LensRef.TestEnv: coeval__ :: (Prog m () -> m) -> ProgramViewT (Inst m) (State (Seq Any)) a -> Prog' b -> StateT (ST m) Er (Maybe a, Prog' b)
- Data.LensRef.TestEnv: data Any
- Data.LensRef.TestEnv: data Inst t a
- Data.LensRef.TestEnv: data Inst' a
- Data.LensRef.TestEnv: data Listener m
- Data.LensRef.TestEnv: data ST m
- Data.LensRef.TestEnv: error' :: String -> ProgramT Inst' m ()
- Data.LensRef.TestEnv: fail' :: MonadWriter [Either (Either a b1) b] m => b1 -> m ()
- Data.LensRef.TestEnv: getProg' :: Prog' b -> StateT s Er b
- Data.LensRef.TestEnv: handEr :: [Char] -> Writer [Either (Either [Char] [Char]) [Char]] () -> [[Char]]
- Data.LensRef.TestEnv: idcounter :: Lens' (ST m_adW8) Int
- Data.LensRef.TestEnv: instance Eq (Port a)
- Data.LensRef.TestEnv: instance Eq Id
- Data.LensRef.TestEnv: instance NewRef (Prog t)
- Data.LensRef.TestEnv: instance Num (Port a)
- Data.LensRef.TestEnv: instance Show (Port a)
- Data.LensRef.TestEnv: instance Show Id
- Data.LensRef.TestEnv: listen :: (MonadRegister m, EffectM m ~ Prog t, Show a) => Port a -> (a -> Modifier m ()) -> m ()
- Data.LensRef.TestEnv: listenerId :: Lens' (Listener m_ab3L) Id
- Data.LensRef.TestEnv: listenerStatus :: Lens' (Listener m_ab3L) RegionStatusChange
- Data.LensRef.TestEnv: listeners :: Lens' (ST m_adW8) [Listener m_adW8]
- Data.LensRef.TestEnv: message :: (MonadRegister m, EffectM m ~ Prog t) => String -> m ()
- Data.LensRef.TestEnv: message' :: String -> ProgramT Inst' m ()
- Data.LensRef.TestEnv: newtype Id
- Data.LensRef.TestEnv: newtype Port a
- Data.LensRef.TestEnv: postponed :: Lens' (ST m_adW8) [m_adW8]
- Data.LensRef.TestEnv: runReg :: (MonadRegisterRun tm, m ~ EffectM tm) => m (AsocT tm) -> (AsocT tm -> m ()) -> tm a -> m (a, m ())
- Data.LensRef.TestEnv: runTest_ :: (Eq a, Show a, m ~ Prog n) => String -> (Prog n () -> n) -> (m n -> (n -> m ()) -> tm a -> m (a, m ())) -> tm a -> Prog' (a, Prog' ()) -> IO ()
- Data.LensRef.TestEnv: send :: Show a => Port a -> a -> ProgramT Inst' m ()
- Data.LensRef.TestEnv: showRes :: [Char] -> ((), [Either (Either [Char] [Char]) [Char]]) -> [[Char]]
- Data.LensRef.TestEnv: tell_ :: MonadWriter [Either a b] m => b -> m ()
- Data.LensRef.TestEnv: type Er = Writer [Either (Either String String) String]
- Data.LensRef.TestEnv: type Prog t = ProgramT (Inst t) (State (Seq Any))
- Data.LensRef.TestEnv: type Prog' = Program Inst'
- Data.LensRef.TestEnv: unPort :: Port a -> Int
- Data.LensRef.TestEnv: unfail :: MonadWriter [Either (Either a b1) b] m => a -> m ()
- Data.LensRef.TestEnv: vars :: Lens' (ST m_adW8) (Seq Any)
Files
- changelog +7/−0
- lensref.cabal +25/−15
- runtests.hs +10/−0
- src/Control/Lens/Simple.hs +63/−0
- src/Data/LensRef.hs +1/−1
- src/Data/LensRef/Default.hs +0/−15
- src/Data/LensRef/Fast.hs +10/−1
- src/Data/LensRef/Pure.hs +17/−13
- src/Data/LensRef/TestEnv.hs +4/−1
changelog view
@@ -1,4 +1,11 @@ += lensref-0.2 =++* Do not always build tests+* 'cabal test' support+* Eliminate dependency on lens, operational and containers packages+* Add lower bound to transformers package dependency+ = lensref-0.1.0.5 = another bugfix for hackagedb
lensref.cabal view
@@ -1,5 +1,5 @@ name: lensref-version: 0.1.0.5+version: 0.2 category: Control, Data synopsis: References which can be joined and on which lenses can be applied description:@@ -43,7 +43,7 @@ homepage: http://www.haskell.org/haskellwiki/LGtk bug-reports: https://github.com/divipp/lensref/issues maintainer: divipp@gmail.com-cabal-version: >= 1.8+cabal-version: >= 1.9.2 build-type: Simple extra-source-files: changelog @@ -51,35 +51,36 @@ type: git location: https://github.com/divipp/lensref.git -Flag Pure- Description: Use the pure but slow implementation+Flag tests+ Description: Build the tests Default: False - library hs-source-dirs: src build-depends: base < 5- , transformers < 0.5+ , transformers >= 0.3 && < 0.5 , mtl < 2.3 , monad-control < 0.4- , operational < 0.3- , lens < 4.2- , containers < 0.6- exposed-modules: Data.LensRef Data.LensRef.Common- Data.LensRef.TestEnv- Data.LensRef.Test Data.LensRef.Pure Data.LensRef.Fast- Data.LensRef.Default- if flag(Pure)+ other-modules:+ Control.Lens.Simple+ if flag(tests) cpp-options:- -D__PURE__+ -D__TESTS__+ build-depends:+ operational < 0.3+ , containers < 0.6+ , lens < 4.2+ exposed-modules:+ Data.LensRef.TestEnv+ Data.LensRef.Test ghc-options: -Wall @@ -88,4 +89,13 @@ -fno-warn-missing-signatures -fno-warn-orphans -fno-warn-type-defaults++test-suite runtests++ type: exitcode-stdio-1.0+ main-is: runtests.hs+ build-depends:+ base < 5+ , lensref+
+ runtests.hs view
@@ -0,0 +1,10 @@+module Main where++import qualified Data.LensRef.Pure as Pure+import qualified Data.LensRef.Fast as Fast++main :: IO ()+main = do+ Pure.runTests+ Fast.runTests+
+ src/Control/Lens/Simple.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE FlexibleInstances #-}+-- | Minimalized lens dependency. Compatible with the lens package.+module Control.Lens.Simple where++import Control.Applicative+import Control.Monad.Identity+import Control.Monad.Reader+import Control.Monad.State++-----------++type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t++type Lens' s a = Lens s s a a++lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b+lens sa sbt afb s = sbt s <$> afb (sa s)++set :: Lens s t a b -> b -> s -> t+set l s = runIdentity . l (const $ Identity s)++united :: Lens' a ()+united f v = fmap (\() -> v) $ f ()++infixl 8 ^.++(^.) :: a -> Lens' a b -> b+a ^. l = getConst $ l Const a++view :: MonadReader s m => Lens' s a -> m a+view l = asks (^. l)++(.=) :: MonadState s m => Lens' s a -> a -> m ()+l .= a = modify $ set l a++magnify :: Monad m => Lens' a b -> ReaderT b m c -> ReaderT a m c+magnify l (ReaderT f) = ReaderT $ \a -> f $ a ^. l++class Field1 s t a b | s -> a, t -> b, s b -> t, t a -> s where+ _1 :: Lens s t a b++instance Field1 (a,b) (a',b) a a' where+ _1 k ~(a,b) = k a <&> \a' -> (a',b)++infixl 1 <&>++(<&>) :: Functor f => f a -> (a -> b) -> f b+as <&> f = f <$> as++class Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s where+ _2 :: Lens s t a b++instance Field2 (a,b) (a,b') b b' where+ _2 k ~(a,b) = k b <&> \b' -> (a,b')++instance Field2 (a,b,c,d) (a,b',c,d) b b' where+ _2 k ~(a,b,c,d) = k b <&> \b' -> (a,b',c,d)++
src/Data/LensRef.hs view
@@ -50,7 +50,7 @@ import Control.Monad import Control.Monad.Identity-import Control.Lens (Lens', set, united)+import Control.Lens.Simple (Lens', set, united) --------------------------------
− src/Data/LensRef/Default.hs
@@ -1,15 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE RankNTypes #-}--- | Default implementation. Points to either to the pure or the fast implementation depending on the cabal flag @PURE@.-module Data.LensRef.Default- ( Register- , runRegister- ) where--#ifdef __PURE__-import Data.LensRef.Pure-#else-import Data.LensRef.Fast-#endif--
src/Data/LensRef/Fast.hs view
@@ -6,6 +6,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE CPP #-} --{-# OPTIONS_HADDOCK hide #-} {- | Fast implementation for the @MonadRefCreator@ interface.@@ -25,12 +26,14 @@ import Control.Applicative hiding (empty) import Control.Monad.State import Control.Monad.Reader-import Control.Lens+import Control.Lens.Simple import Data.LensRef import Data.LensRef.Common+#ifdef __TESTS__ import Data.LensRef.TestEnv import Data.LensRef.Test+#endif ---------------------- @@ -290,6 +293,7 @@ -------------------------- +#ifdef __TESTS__ instance MonadRegisterRun (Register (Prog TP)) where type AsocT (Register (Prog TP)) = TP@@ -298,6 +302,7 @@ newtype TP = TP { unTP :: Wrap (Prog TP) () } +runTests :: IO () runTests = do mkTests runTestSimple tests runTest@@ -308,4 +313,8 @@ runTestSimple :: Register (Prog TP) () -> IO () runTestSimple m = runTest "" m $ return ((), return ())+#else+runTests :: IO ()+runTests = fail "enable the tests flag like \'cabal configure --enable-tests -ftests; cabal build; cabal test\'"+#endif
src/Data/LensRef/Pure.hs view
@@ -8,6 +8,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE CPP #-} -- {-# OPTIONS_HADDOCK hide #-} {- | Register reference implementation for the @MonadRefCreator@ interface.@@ -24,17 +25,16 @@ import Control.Applicative import Control.Monad.State import Control.Monad.Reader-import Control.Arrow (second)-import qualified Data.Sequence as Seq-import Control.Lens hiding ((|>))-import Data.Foldable (toList)+import Control.Lens.Simple import Unsafe.Coerce import Data.LensRef import Data.LensRef.Common+#ifdef __TESTS__ import Data.LensRef.TestEnv import Data.LensRef.Test+#endif ---------------------- @@ -44,12 +44,12 @@ ---------------------- -newtype Lens_ a b = Lens_ {unLens_ :: ALens' a b}+newtype Lens_ a b = Lens_ {unLens_ :: Lens' a b} runLens_ :: Reader a (Lens_ a b) -> Lens' a b-runLens_ r f a = cloneLens (unLens_ $ runReader r a) f a+runLens_ r f a = unLens_ (runReader r a) f a -type LSt = Seq.Seq CC+type LSt = [CC] data CC = forall a . CC (LSt -> a -> a) a @@ -70,7 +70,7 @@ instance RefClass (Lens_ LSt) where type RefReaderSimple (Lens_ LSt) = Reader LSt - readRefSimple = view . runLens_+ readRefSimple r = view $ runLens_ r writeRefSimple r a = runLens_ r .= a lensMap l r = return $ Lens_ $ runLens_ r . l unitRef = return $ Lens_ united@@ -86,13 +86,13 @@ rk = set (runLens_ r) . (^. r2) kr = set r2 . (^. runLens_ r) - extend x0 = (return $ Lens_ $ lens get set, x0 Seq.|> CC kr (kr x0 a0))+ extend x0 = (return $ Lens_ $ lens get set, x0 ++ [CC kr (kr x0 a0)]) where- limit = second toList . Seq.splitAt (Seq.length x0)+ limit = splitAt (length x0) get = unsafeData . head . snd . limit - set x a = foldl (\x -> (Seq.|>) x . ap_ x) (rk a zs Seq.|> CC kr a) ys where+ set x a = foldl (\x -> (x++) . (:[]) . ap_ x) (rk a zs ++ [CC kr a]) ys where (zs, _ : ys) = limit x ap_ :: LSt -> CC -> CC@@ -251,6 +251,7 @@ ------------------------ +#ifdef __TESTS__ instance MonadRegisterRun (Register (Prog TP)) where type AsocT (Register (Prog TP)) = TP@@ -259,6 +260,7 @@ newtype TP = TP { unTP :: SLSt (Prog TP) () } +runTests :: IO () runTests = do mkTests runTestSimple tests runTest@@ -269,6 +271,8 @@ runTestSimple :: Register (Prog TP) () -> IO () runTestSimple m = runTest "" m $ return ((), return ())--+#else+runTests :: IO ()+runTests = fail "enable the tests flag like \'cabal configure --enable-tests -ftests; cabal build; cabal test\'"+#endif
src/Data/LensRef/TestEnv.hs view
@@ -244,12 +244,15 @@ -> tm a -> Prog' (a, Prog' ()) -> IO ()-runTest_ name lift runRegister_ r p0 = putStr $ unlines $ handEr name $ flip evalStateT (ST [] [] 0 Seq.empty) $ do+runTest_ name lift runRegister_ r p0 = showError $ handEr name $ flip evalStateT (ST [] [] 0 Seq.empty) $ do (Just (a1,c),pe) <- coeval_ lift (runRegister_ (singleton ReadI) (singleton . WriteI) r) p0 (a2,p) <- getProg' pe when (a1 /= a2) $ fail' $ "results differ: " ++ show a1 ++ " vs " ++ show a2 (_, pr) <- coeval_ lift c p getProg' pr++showError [] = return ()+showError xs = fail $ "\n" ++ unlines xs ------------------------------------------------