-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Extensible objects -- -- Stateful effect transducer @package objective @version 0.6.3.2 module Data.Functor.Request -- | 'Request a b' is the type of a request that sends a to -- receive b. data Request a b r Request :: a -> (b -> r) -> Request a b r mapRequest :: (a -> a') -> Request a b r -> Request a' b r request :: Elevate (Request a b) f => a -> f b accept :: Functor f => (a -> f b) -> Request a b r -> f r acceptM :: Monad m => (a -> m b) -> Request a b r -> m r instance Typeable Request instance Functor (Request a b) instance Tower (Request a b) instance Monoid a => Applicative (Request a b) instance Profunctor (Request a) module Data.Functor.PushPull -- | The type for asynchronous input/output. data PushPull a b r Push :: a -> r -> PushPull a b r Pull :: (b -> r) -> PushPull a b r type PushPull' a = PushPull a a mapPush :: (a -> a') -> PushPull a b r -> PushPull a' b r push :: Elevate (PushPull a b) f => a -> f () pull :: Elevate (PushPull a b) f => f b bipush :: (i -> (a, c)) -> (b -> d -> o) -> PushPull i o r -> Day (PushPull a b) (PushPull c d) r bipull :: (a -> b -> c) -> PushPull i c r -> Day (PushPull i a) (PushPull i b) r -- |
-- filterPush :: (a -> Bool) -> PushPull a b r -> Program (PushPull a b) r --filterPush :: (Applicative f, Elevate (PushPull a b) f) => (a -> Bool) -> PushPull a b r -> f r instance Typeable PushPull instance Functor (PushPull a b) instance Tower (PushPull a b) instance Profunctor (PushPull a) -- | Stateful effect transducer: The Mealy machine for effects. module Control.Object -- | The type Object f g represents objects which can handle -- messages f, perform actions in the environment g. It -- can be thought of as an automaton that converts effects. -- Objects can be composed just like functions using -- @>>@; the identity element is echo. Objects are -- morphisms of the category of functors newtype Object f g Object :: (forall x. f x -> g (x, Object f g)) -> Object f g runObject :: Object f g -> forall x. f x -> g (x, Object f g) -- | An alias for runObject. (@-) :: Object f g -> f x -> g (x, Object f g) -- | Lift a natural transformation into an object. liftO :: Functor g => (forall x. f x -> g x) -> Object f g -- | The identity object echo :: Functor f => Object f f -- | Build an object using continuation passing style. oneshot :: (Functor f, Monad m) => (forall a. f (m a) -> m a) -> Object f m -- | Build a stateful object. -- -- stateful t s = t ^>> variable s@ stateful :: Monad m => (forall a. f a -> StateT s m a) -> s -> Object f m -- | A mutable variable. variable :: s -> Variable s type Variable s = forall m. Monad m => Object (StateT s m) m -- | The unwrapped analog of stateful unfoldO runObject = -- id unfoldO runSequential = sequential unfoldO -- iterObject = iterable unfoldO :: Functor g => (forall a. r -> f a -> g (a, r)) -> r -> Object f g unfoldOM :: Monad m => (forall a. r -> f a -> m (a, r)) -> r -> Object f m foldP :: Applicative f => (a -> r -> f r) -> r -> Object (PushPull a r) f foldP' :: Applicative f => (a -> r -> r) -> r -> Object (PushPull a r) f -- | Build a stateful object, sharing out the state. sharing :: Monad m => (forall a. f a -> StateT s m a) -> s -> Object (State s |> (f |> Nil)) m animate :: (Applicative m, Num t) => (t -> m a) -> Object (Request t a) m transit :: (Alternative m, Fractional t, Ord t) => t -> (t -> m a) -> Object (Request t a) m -- | Object-object composition (@>>@) :: Functor h => Object f g -> Object g h -> Object f h -- | Object-function composition (@>>^) :: Functor h => Object f g -> (forall x. g x -> h x) -> Object f h -- | Function-object composition (^>>@) :: Functor h => (forall x. f x -> g x) -> Object g h -> Object f h (@**@) :: Applicative m => Object f m -> Object g m -> Object (Day f g) m (@||@) :: Functor m => Object f m -> Object g m -> Object (Sum f g) m -- | An object that won't accept any messages. loner :: Functor f => Object Nil f -- | Extend an object by adding another independent object. (@|>@) :: Functor g => Object f g -> Object (Union s) g -> Object (f |> Union s) g -- | Change the workspace of the object. transObject :: Functor g => (forall x. f x -> g x) -> Object e f -> Object e g -- | Apply a function to the messages coming into the object. adaptObject :: Functor m => (forall x. g x -> f x) -> Object f m -> Object g m -- | For every adjunction f ⊣ g, we can "connect" Object g m and -- Object f m permanently. ($$) :: (Monad m, Adjunction f g) => Object g m -> Object f m -> m x -- | Like $$, but kept until the right Mortal dies. ($$!) :: (Monad m, Adjunction f g) => Object g m -> Mortal f m a -> m (Object g m, a) -- | Like $$, but kept until the left Mortal dies. (!$$) :: (Monad m, Adjunction f g) => Mortal g m a -> Object f m -> m (a, Object f m) -- | Connect two Mortals. (!$$!) :: (Monad m, Adjunction f g) => Mortal g m a -> Mortal f m b -> m (Either (a, Mortal f m b) (Mortal g m a, b)) (@!) :: Monad m => Object e m -> ReifiedProgram e a -> m (a, Object e m) (@!!) :: Monad m => Object e m -> ReifiedProgramT e m a -> m (a, Object e m) -- | Let object handle sequential methods. sequential :: Monad m => Object e m -> Object (ReifiedProgram e) m -- | Let object handle sequential methods. sequentialT :: Monad m => Object e m -> Object (ReifiedProgramT e m) m iterObject :: Monad m => Object f m -> Free f a -> m (a, Object f m) iterTObject :: Monad m => Object f m -> FreeT f m a -> m (a, Object f m) iterative :: Monad m => Object f m -> Object (Free f) m iterativeT :: Monad m => Object f m -> Object (FreeT f m) m -- | The flyweight pattern. flyweight :: (Monad m, Ord k) => (k -> m a) -> Object (Request k a) m -- | Like flyweight, but it uses Strict internally. flyweight' :: (Monad m, Eq k, Hashable k) => (k -> m a) -> Object (Request k a) m announce :: (Traversable t, Monad m, Elevate (State (t (Object f g))) m, Elevate g m) => f a -> m [a] announceMaybe :: (Witherable t, Monad m, Elevate (State (t (Object f Maybe))) m) => f a -> m [a] announceMaybeT :: (Witherable t, Monad m, State (t (Object f (MaybeT g))) ∈ Floors1 m, g ∈ Floors1 m, Tower m) => f a -> m [a] announceMortal :: (Witherable t, Monad m, State (t (Mortal f g ())) ∈ Floors1 m, g ∈ Floors1 m, Tower m) => f a -> m [a] -- | An object which is specialized to be a Mealy machine newtype Process m a b Process :: Object (Request a b) m -> Process m a b unProcess :: Process m a b -> Object (Request a b) m -- |
-- _Process :: Iso' (Object (Request a b) m) (Process m a b) --_Process :: (Profunctor p, Functor f) => p (Process m a b) (f (Process m a b)) -> p (Object (Request a b) m) (f (Object (Request a b) m)) -- | Object with a final result. -- --
-- Object f g ≡ Mortal f g Void --newtype Mortal f g a Mortal :: Object f (EitherT a g) -> Mortal f g a unMortal :: Mortal f g a -> Object f (EitherT a g) runMortal :: Mortal f m a -> f x -> m (Either a (x, Mortal f m a)) instance Typeable Object instance Monad m => Monad (Mortal f m) instance (Functor m, Monad m) => Applicative (Mortal f m) instance (Functor m, Monad m) => Functor (Mortal f m) instance (Applicative m, Fractional o) => Fractional (Process m i o) instance (Applicative m, Num o) => Num (Process m i o) instance Monad m => Choice (Process m) instance Monad m => Strong (Process m) instance Monad m => Profunctor (Process m) instance Monad m => ArrowChoice (Process m) instance Monad m => Arrow (Process m) instance Monad m => Category (Process m) instance (Applicative f, Monoid b) => Monoid (Process f a b) instance Applicative f => Applicative (Process f a) instance Functor f => Functor (Process f a) -- | MonadObjective class and operations module Control.Monad.Objective.Class type Inst' f g = Inst g f g class Monad b => ObjectiveBase b where data family Inst b (f :: * -> *) (g :: * -> *) type family InstOf b o :: * type instance InstOf b (Object f g) = Inst b f g new :: ObjectiveBase b => Object f g -> b (Inst b f g) invoke :: (ObjectiveBase b, Monad m) => (forall x. b x -> m x) -> (forall x. g x -> m x) -> Inst b f g -> f a -> m a type MonadObjective b m = (ObjectiveBase b, Elevate b m, Monad m) (.-) :: (MonadObjective b m, Elevate g m) => Inst b f g -> f a -> m a -- | Invoke a method. (.^) :: (MonadObjective b m, Elevate g m, Elevate e f) => Inst b f g -> e a -> m a -- | (.^) for StateT (.&) :: (MonadObjective b m, Elevate g m, Elevate (State s) f) => Inst b f g -> StateT s m a -> m a (.!) :: (MonadObjective b m, Elevate g m) => Inst b f g -> Program f a -> m a -- | We can convert method invocation into an object trivially. -- invocation i = liftO (i.-) invocation :: (MonadObjective b m, Elevate g m) => Inst b f g -> Object f m -- | MonadObjective IO using MVar module Control.Monad.Objective.IO newIO :: MonadIO m => Object f g -> m (Inst IO f g) instance ObjectiveBase IO -- | MonadObjective ST using STRef module Control.Monad.Objective.ST newST :: Elevate (ST s) m => Object f g -> m (Inst (ST s) f g) instance ObjectiveBase (ST s) module Control.Monad.Objective