remote-monad

An parametrizable Remote Monad, and parametrizable Applicative Functor

Latest on Hackage:0.2@rev:1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD-3-Clause licensed by Andy Gill, Justin Dawson
Maintained by [email protected]

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")