free-operational 0.4.0.0 → 0.5.0.0
raw patch · 8 files changed
+49/−39 lines, 8 filesdep ~QuickCheckdep ~free-operationaldep ~kan-extensions
Dependency ranges changed: QuickCheck, free-operational, kan-extensions, mtl, test-framework, test-framework-quickcheck2
Files
- Control/Alternative/Operational.hs +4/−4
- Control/Applicative/Operational.hs +4/−4
- Control/Monad/Operational.hs +2/−2
- Control/Monad/Operational/Simple.hs +3/−3
- Control/Monad/Trans/Operational.hs +5/−5
- Control/MonadPlus/Operational.hs +6/−6
- Control/Operational/Instruction.hs +7/−5
- free-operational.cabal +18/−10
Control/Alternative/Operational.hs view
@@ -167,11 +167,11 @@ import Control.Alternative.Free hiding (Pure) import Control.Operational.Class import Control.Operational.Instruction-import Data.Functor.Yoneda.Reduction+import Data.Functor.Coyoneda newtype ProgramAlt instr a = ProgramAlt { -- | Interpret the program as a free 'Alternative' ('Alt').- toAlt :: Alt (Yoneda instr) a + toAlt :: Alt (Coyoneda instr) a } deriving (Functor, Applicative, Alternative) instance Operational instr (ProgramAlt instr) where@@ -198,9 +198,9 @@ viewAlt :: ProgramAlt instr a -> ProgramViewAlt instr a viewAlt = viewAlt' . toAlt -viewAlt' :: Alt (Yoneda instr) a -> ProgramViewAlt instr a+viewAlt' :: Alt (Coyoneda instr) a -> ProgramViewAlt instr a viewAlt' (Free.Pure a) = Pure a-viewAlt' (Free.Ap (Yoneda f i) next) = i :<**> viewAlt' (fmap (.f) next)+viewAlt' (Free.Ap (Coyoneda f i) next) = i :<**> viewAlt' (fmap (.f) next) viewAlt' (Free.Alt xs) = Many $ map viewAlt' xs
Control/Applicative/Operational.hs view
@@ -24,7 +24,7 @@ import qualified Control.Applicative.Free as Free import Control.Operational.Class import Control.Operational.Instruction-import Data.Functor.Yoneda.Reduction+import Data.Functor.Coyoneda -- | An 'Applicative' program over instruction set @instr@. This is@@ -43,7 +43,7 @@ -- See also the examples in "Control.Alternative.Operational". newtype ProgramAp instr a = ProgramAp { -- | Interpret a 'ProgramAp' as a free applicative ('Ap').- toAp :: Ap (Yoneda instr) a + toAp :: Ap (Coyoneda instr) a } deriving (Functor, Applicative) instance Operational instr (ProgramAp instr) where@@ -174,9 +174,9 @@ viewAp :: ProgramAp instr a -> ProgramViewAp instr a viewAp = viewAp' . toAp -viewAp' :: Ap (Yoneda instr) a -> ProgramViewAp instr a+viewAp' :: Ap (Coyoneda instr) a -> ProgramViewAp instr a viewAp' (Free.Pure a) = Pure a-viewAp' (Free.Ap (Yoneda f i) next) = i :<**> viewAp' (fmap (.f) next)+viewAp' (Free.Ap (Coyoneda f i) next) = i :<**> viewAp' (fmap (.f) next) -- | Compile a 'ProgramViewAp' back into a 'ProgramAp'. compileAp :: ProgramViewAp instr a -> ProgramAp instr a
Control/Monad/Operational.hs view
@@ -42,14 +42,14 @@ import Control.Monad.Trans.Operational import Control.Operational.Class import Control.Operational.Instruction-import Data.Functor.Yoneda.Reduction+import Data.Functor.Coyoneda -- | Drop-in replacement for @operational@'s type synonym. type Program instr = ProgramT instr Identity -- | The 'Free' monad action for a 'Program'.-toFree :: Program instr a -> Free (Yoneda instr) a+toFree :: Program instr a -> Free (Coyoneda instr) a toFree = freeT2Free . toFreeT where freeT2Free :: Functor f => FreeT f Identity a -> Free f a
Control/Monad/Operational/Simple.hs view
@@ -18,12 +18,12 @@ import Control.Monad.Free import Control.Operational.Class import Control.Operational.Instruction-import Data.Functor.Yoneda.Reduction+import Data.Functor.Coyoneda newtype Program instr a = Program { -- | Intepret the program as a 'Free' monad.- toFree :: Free (Yoneda instr) a + toFree :: Free (Coyoneda instr) a } deriving (Functor, Applicative, Monad) instance Operational instr (Program instr) where@@ -50,4 +50,4 @@ view :: Program instr a -> ProgramView instr a view = eval . toFree where eval (Pure a) = Return a- eval (Free (Yoneda f i)) = i :>>= (Program . f)+ eval (Free (Coyoneda f i)) = i :>>= (Program . f)
Control/Monad/Trans/Operational.hs view
@@ -17,11 +17,11 @@ import Control.Monad.Trans.Free import Control.Operational.Class import Control.Operational.Instruction-import Data.Functor.Yoneda.Reduction+import Data.Functor.Coyoneda newtype ProgramT instr m a = - ProgramT { toFreeT :: FreeT (Yoneda instr) m a + ProgramT { toFreeT :: FreeT (Coyoneda instr) m a } deriving (Functor, Applicative, Monad, MonadTrans) instance Monad m => Operational instr (ProgramT instr m) where@@ -44,8 +44,8 @@ interpretT evalI = retractT . transFreeT evalF . toFreeT where evalF :: forall m x. (Functor (t m), Monad (t m), Functor m, Monad m) => - Yoneda instr x -> t m x- evalF (Yoneda f i) = fmap f (evalI i)+ Coyoneda instr x -> t m x+ evalF (Coyoneda f i) = fmap f (evalI i) retractT :: (MonadTrans t, Functor (t m), Monad (t m), Monad m) => FreeT (t m) m a -> t m a@@ -83,5 +83,5 @@ viewT :: Monad m => ProgramT instr m a -> m (ProgramViewT instr m a) viewT = liftM eval . runFreeT . toFreeT where eval (Pure a) = Return a- eval (Free (Yoneda f i)) = i :>>= ProgramT . f+ eval (Free (Coyoneda f i)) = i :>>= ProgramT . f
Control/MonadPlus/Operational.hs view
@@ -19,23 +19,23 @@ import Control.Monad import Control.MonadPlus.Free import Control.Operational.Class-import Data.Functor.Yoneda.Reduction+import Data.Functor.Coyoneda newtype ProgramP instr a = ProgramP { -- | Interpret the program as a free 'MonadPlus'.- toFree :: Free (Yoneda instr) a + toFree :: Free (Coyoneda instr) a } deriving (Functor, Applicative, Alternative, Monad, MonadPlus) instance Operational instr (ProgramP instr) where- singleton = ProgramP . liftF . liftYoneda+ singleton = ProgramP . liftF . liftCoyoneda interpretP :: forall m instr a. (Functor m, MonadPlus m) => (forall x. instr x -> m x) -> ProgramP instr a -> m a interpretP evalI = retract . hoistFree evalF . toFree- where evalF :: forall x. Yoneda instr x -> m x- evalF (Yoneda f i) = fmap f (evalI i)+ where evalF :: forall x. Coyoneda instr x -> m x+ evalF (Coyoneda f i) = fmap f (evalI i) fromProgramP :: (Operational instr m, Functor m, MonadPlus m) => ProgramP instr a -> m a@@ -50,5 +50,5 @@ view :: ProgramP instr a -> ProgramViewP instr a view = eval . toFree where eval (Pure a) = Return a- eval (Free (Yoneda f i)) = i :>>= (ProgramP . f)+ eval (Free (Coyoneda f i)) = i :>>= (ProgramP . f) eval (Plus mas) = MPlus $ map eval mas
Control/Operational/Instruction.hs view
@@ -22,13 +22,15 @@ ) where import Data.Functor.Coproduct-import Data.Functor.Yoneda.Reduction+import Data.Functor.Coyoneda -- | Lift an operational instruction evaluator into a free 'Functor' -- evaluator.-liftEvalI :: Functor f => (forall x. instr x -> f x) -> Yoneda instr a -> f a-liftEvalI evalI (Yoneda f i) = fmap f (evalI i) +liftEvalI :: Functor f => + (forall x. instr x -> f x)+ -> Coyoneda instr a -> f a+liftEvalI evalI (Coyoneda f i) = fmap f (evalI i) -liftInstr :: instr a -> Yoneda instr a-liftInstr = liftYoneda+liftInstr :: instr a -> Coyoneda instr a+liftInstr = liftCoyoneda
free-operational.cabal view
@@ -1,6 +1,6 @@ name: free-operational category: Control-version: 0.4.0.0+version: 0.5.0.0 build-type: Simple cabal-version: >=1.8 synopsis: Operational Applicative, Alternative, Monad and MonadPlus from free types.@@ -43,18 +43,26 @@ location: https://github.com/sacundim/free-operational +-- Build the properties test if we're building tests+flag test-properties+ default: False+ manual: True+ test-suite tests type: exitcode-stdio-1.0 hs-source-dirs: tests Main-is: Properties.hs- build-depends: base ==4.*,- mtl >=2.1,- transformers >=0.3,- free-operational >=0.2,- test-framework >=0.8,- test-framework-quickcheck2 >=0.3, - QuickCheck >=2.5,- checkers ==0.3.1+ if !flag(test-properties)+ buildable: False+ else+ build-depends: base ==4.*,+ mtl >=2,+ transformers >=0.3,+ free-operational >=0.3,+ test-framework >=0.6,+ test-framework-quickcheck2 >=0.2, + QuickCheck >=2.4,+ checkers ==0.3.1 library exposed-modules: Control.Operational.Class,@@ -71,5 +79,5 @@ mtl >=2, free >=3.3, comonad-transformers >=3.0,- kan-extensions >=3.5+ kan-extensions >=3.7 && <3.8