-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An parametrizable Remote Monad, and parametrizable Applicative Functor -- -- An implementation of the concepts behind Remote Monads. There is -- support for various bundling strategies. -- --
-- {-# LANGUAGE GADTs #-}
-- {-# LANGUAGE KindSignatures #-}
--
-- module Main where
--
-- import Control.Natural (nat, (#))
-- import Control.Remote.Monad
-- import Control.Remote.Monad.Packet.Weak
--
-- data Command :: * where
-- Say :: String -> Command
--
-- data Procedure :: * -> * where
-- Temperature :: Procedure Int
--
-- say :: String -> RemoteMonad Command Procedure ()
-- say s = command (Say s)
--
-- temperature :: RemoteMonad Command Procedure Int
-- temperature = procedure Temperature
--
-- runWP :: WeakPacket Command Procedure a -> IO a
-- runWP (Command (Say s)) = print s
-- runWP (Procedure Temperature) = return 42
--
-- send :: RemoteMonad Command Procedure a -> IO a
-- send = run $ runMonad $ nat runWP
--
-- main = send $ do
-- say "Howdy doodly do"
-- say "How about a muffin?"
-- t <- temperature
-- say (show t ++ "F")
--
@package remote-monad
@version 0.2
module Control.Remote.Monad.Packet.Weak
-- | A Weak Packet, that can encode a command or a procedure.
data WeakPacket (c :: *) (p :: * -> *) (a :: *)
Command :: c -> WeakPacket c p ()
Procedure :: p a -> WeakPacket c p a
instance (GHC.Show.Show c, GHC.Show.Show (p a)) => GHC.Show.Show (Control.Remote.Monad.Packet.Weak.WeakPacket c p a)
instance (GHC.Read.Read c, GHC.Read.Read (Control.Remote.Monad.Packet.Transport.Transport p)) => GHC.Read.Read (Control.Remote.Monad.Packet.Transport.Transport (Control.Remote.Monad.Packet.Weak.WeakPacket c p))
module Control.Remote.Monad.Packet.Strong
-- | A Strong Packet, that can encode a list of commands, terminated by an
-- optional procedure.
data StrongPacket (c :: *) (p :: * -> *) (a :: *)
Command :: c -> StrongPacket c p b -> StrongPacket c p b
Procedure :: p a -> StrongPacket c p a
Done :: StrongPacket c p ()
-- | A Hughes-style version of StrongPacket, with efficent append.
newtype HStrongPacket c p
HStrongPacket :: (StrongPacket c p ~> StrongPacket c p) -> HStrongPacket c p
module Control.Remote.Monad.Packet.Applicative
-- | A Remote Applicative, that can encode both commands and procedures,
-- bundled together.
data ApplicativePacket (c :: *) (p :: * -> *) (a :: *)
Command :: ApplicativePacket c p b -> c -> ApplicativePacket c p b
Procedure :: ApplicativePacket c p (a -> b) -> p a -> ApplicativePacket c p b
Pure :: a -> ApplicativePacket c p a
-- | This simulates a ApplicativePacket, to see if it only contains
-- commands, and if so, returns the static result. The commands still
-- need executed. The term super-command is a play on Hughes'
-- super-combinator terminology.
superCommand :: ApplicativePacket c p a -> Maybe a
instance GHC.Base.Functor (Control.Remote.Monad.Packet.Applicative.ApplicativePacket c p)
instance GHC.Base.Applicative (Control.Remote.Monad.Packet.Applicative.ApplicativePacket c p)
module Control.Remote.Applicative
-- | RemoteApplicative is our applicative that can be executed in a
-- remote location.
data RemoteApplicative c p a
-- | promote a command into the applicative
command :: c -> RemoteApplicative c p ()
-- | promote a command into the applicative
procedure :: p a -> RemoteApplicative c p a
-- | RunApplicative is the overloading for choosing the appropriate
-- bundling strategy for applicative.
class RunApplicative f
-- | This overloaded function chooses the appropriate bundling strategy
-- based on the type of the handler your provide.
runApplicative :: (RunApplicative f, Monad m) => (f c p :~> m) -> (RemoteApplicative c p :~> m)
-- | The weak remote applicative, that sends commands and procedures
-- piecemeal.
runWeakApplicative :: (Applicative m) => (WeakPacket c p :~> m) -> (RemoteApplicative c p :~> m)
-- | The strong remote applicative, that bundles together commands.
runStrongApplicative :: (Monad m) => (StrongPacket c p :~> m) -> (RemoteApplicative c p :~> m)
-- | The applicative remote applicative, that is the identity function.
runApplicativeApplicative :: (ApplicativePacket c p :~> m) -> (RemoteApplicative c p :~> m)
instance Control.Remote.Applicative.RunApplicative Control.Remote.Monad.Packet.Weak.WeakPacket
instance Control.Remote.Applicative.RunApplicative Control.Remote.Monad.Packet.Strong.StrongPacket
instance Control.Remote.Applicative.RunApplicative Control.Remote.Monad.Packet.Applicative.ApplicativePacket
module Control.Remote.Monad
-- | RemoteMonad is our monad that can be executed in a remote
-- location.
data RemoteMonad c p a
-- | promote a command into the remote monad
command :: c -> RemoteMonad c p ()
-- | promote a procedure into the remote monad
procedure :: p a -> RemoteMonad c p a
-- | RunMonad is the overloading for choosing the appropriate
-- bundling strategy for a monad.
class RunMonad f
-- | This overloaded function chooses the appropriate bundling strategy
-- based on the type of the handler your provide.
runMonad :: (RunMonad f, Monad m) => (f c p :~> m) -> (RemoteMonad c p :~> m)
-- | This is the classic weak remote monad, or technically the weak remote
-- applicative weak remote monad.
runWeakMonad :: (Monad m) => (WeakPacket c p :~> m) -> (RemoteMonad c p :~> m)
-- | This is the classic strong remote monad. It bundles packets (of type
-- StrongPacket) as large as possible, including over some monadic
-- binds.
runStrongMonad :: (Monad m) => (StrongPacket c p :~> m) -> (RemoteMonad c p :~> m)
-- | The is the strong applicative strong remote monad. It bundles packets
-- (of type RemoteApplicative) as large as possible, including
-- over some monadic binds.
runApplicativeMonad :: (Monad m) => (ApplicativePacket c p :~> m) -> (RemoteMonad c p :~> m)
-- | This is a remote monad combinator, that takes an implementation of a
-- remote applicative, splits the monad into applicatives without any
-- merge stragegy, and uses the remote applicative. Every
-- >>= will generate a call to the RemoteApplicative
-- handler; as well as one terminating call. Using
-- runBindeeMonad with a runWeakApplicative gives the
-- weakest remote monad.
runMonadSkeleton :: (Monad m) => (RemoteApplicative c p :~> m) -> (RemoteMonad c p :~> m)
instance Control.Remote.Monad.RunMonad Control.Remote.Monad.Packet.Weak.WeakPacket
instance Control.Remote.Monad.RunMonad Control.Remote.Monad.Packet.Strong.StrongPacket
instance Control.Remote.Monad.RunMonad Control.Remote.Monad.Packet.Applicative.ApplicativePacket