use ExceptT

This commit is contained in:
Evgeny Poberezkin
2020-05-31 22:37:08 +01:00
parent cc55bf3e6b
commit d74c109328
4 changed files with 20 additions and 16 deletions
+1
View File
@@ -38,6 +38,7 @@ dependencies:
- servant-docs
- servant-server
- template-haskell
- transformers
library:
source-dirs: src
+4 -3
View File
@@ -8,13 +8,14 @@
module Simplex.Messaging.Broker where
import Control.Monad.Trans.Except
import Simplex.Messaging.Protocol
instance Monad m => PartyProtocol m Broker where
api ::
Command from fs fs' Broker ps ps' res ->
Connection Broker ps ->
m (Either String (res, Connection Broker ps'))
ExceptT String m (res, Connection Broker ps')
api (CreateConn _) = apiStub
api (Subscribe _) = apiStub
api (Unsubscribe _) = apiStub
@@ -26,7 +27,7 @@ instance Monad m => PartyProtocol m Broker where
action ::
Command Broker ps ps' to ts ts' res ->
Connection Broker ps ->
Either String res ->
m (Either String (Connection Broker ps'))
ExceptT String m res ->
ExceptT String m (Connection Broker ps')
action (PushConfirm _ _) = actionStub
action (PushMsg _ _) = actionStub
+7 -6
View File
@@ -8,21 +8,22 @@
module Simplex.Messaging.Client where
import Control.Monad.Trans.Except
import Simplex.Messaging.Protocol
instance Monad m => PartyProtocol m Recipient where
api ::
Command from fs fs' Recipient ps ps' res ->
Connection Recipient ps ->
m (Either String (res, Connection Recipient ps'))
ExceptT String m (res, Connection Recipient ps')
api (PushConfirm _ _) = apiStub
api (PushMsg _ _) = apiStub
action ::
Command Recipient ps ps' to ts ts' res ->
Connection Recipient ps ->
Either String res ->
m (Either String (Connection Recipient ps'))
ExceptT String m res ->
ExceptT String m (Connection Recipient ps')
action (CreateConn _) = actionStub
action (Subscribe _) = actionStub
action (Unsubscribe _) = actionStub
@@ -34,13 +35,13 @@ instance Monad m => PartyProtocol m Sender where
api ::
Command from fs fs' Sender ps ps' res ->
Connection Sender ps ->
m (Either String (res, Connection Sender ps'))
ExceptT String m (res, Connection Sender ps')
api (SendInvite _) = apiStub
action ::
Command Sender ps ps' to ts ts' res ->
Connection Sender ps ->
Either String res ->
m (Either String (Connection Sender ps'))
ExceptT String m res ->
ExceptT String m (Connection Sender ps')
action (ConfirmConn _ _) = actionStub
action (SendMsg _ _) = actionStub
@@ -20,6 +20,7 @@
module Simplex.Messaging.Protocol where
import Control.Monad.Trans.Except
import Data.Kind
import Data.Singletons
import Data.Singletons.TH
@@ -118,18 +119,18 @@ class Monad m => PartyProtocol m (p :: Party) where
api ::
Command from fs fs' p ps ps' res ->
Connection p ps ->
m (Either String (res, Connection p ps'))
ExceptT String m (res, Connection p ps')
action ::
Command p ps ps' to ts ts' res ->
Connection p ps ->
Either String res ->
m (Either String (Connection p ps'))
ExceptT String m res ->
ExceptT String m (Connection p ps')
apiStub :: Monad m => Connection p ps -> m (Either String (res, Connection p ps'))
apiStub _ = return $ Left "api not implemented"
apiStub :: Monad m => Connection p ps -> ExceptT String m (res, Connection p ps')
apiStub _ = throwE "api not implemented"
actionStub :: Monad m => Connection p ps -> Either String res -> m (Either String (Connection p ps'))
actionStub _ _ = return $ Left "action not implemented"
actionStub :: Monad m => Connection p ps -> ExceptT String m res -> ExceptT String m (Connection p ps')
actionStub _ _ = throwE "action not implemented"
type AllowedStates from fs fs' to ts ts' =
( HasState from fs,