TYPES

INTRO

The Network.N2O.Types module contains context definition, state and N2O monad.

CONTEXT

Listing 1. N2O Context
data Cx (f :: * -> *) (a :: *) (b :: *) = Cx { cxHandler :: W a -> N2O f a b b , cxReq :: Req , cxMiddleware :: [Cx f a b -> Cx f a b] , cxDePickle :: BL.ByteString -> Maybe a , cxPickle :: a -> BL.ByteString , cxProtos :: [Proto f a b] , cxEncoder :: Encoder b , cxDecoder :: Decoder (f a) , cxState :: Map BS.ByteString BL.ByteString }

STATE

Listing 2. N2O State
type N2OState (f :: * -> *) (a :: *) (b :: *) = IORef (Cx f a b)

MONAD

Listing 2. N2O Monad
type N2O (f :: * -> *) (a :: *) (b :: *) = N2OM (N2OState f a b) IO newtype N2OM state m a = N2OM { runN2O :: state -> m a } instance Functor m => Functor (N2OM state m) instance Applicative m => Applicative (N2OM state m) instance Monad m => Monad (N2OM state m)

lift :: m a -> N2OM state m a

ask :: (Monad m) => N2OM state m state

put :: (B.Binary bin) => BS.ByteString -> bin -> N2O f a b ()

get :: (B.Binary bin) => BS.ByteString -> N2O f a b (Maybe bin)

PROTO

Return formalize Erlang return protocol, Msg relates to WebSocket streaming, Proto is protocol handler.

Listing 1. N2O PROTO
data Return = Reply Msg | Ok | Unknown deriving (Show, Eq) data Proto (f :: * -> *) (a :: *) (b :: *) = Proto { protoInfo :: f a -> N2O f a b Return } data Msg = MsgTxt TL.Text | MsgBin BL.ByteString | MsgInit BL.ByteString | MsgTerminate deriving (Show, Eq)

This module may refer to: INTERNAL, CORE