Skip to content

Commit

Permalink
typed-protocols: added TokPeerRole
Browse files Browse the repository at this point in the history
A singleton type for PeerRole; It is useful when writing application
code that can be shared between client and server.
  • Loading branch information
coot committed Oct 12, 2021
1 parent c834f35 commit b744ede
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions typed-protocols/src/Network/TypedProtocol/Core.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE PolyKinds #-}
Expand All @@ -26,6 +27,7 @@ module Network.TypedProtocol.Core (
-- * Engaging in protocols
-- $using
PeerRole(..),
TokPeerRole(..),
FlipAgency,
PeerHasAgency(..),
WeHaveAgency,
Expand Down Expand Up @@ -320,6 +322,14 @@ class Protocol ps where
--
data PeerRole = AsClient | AsServer

-- | Singletons for the promoted 'PeerRole' types. Not directly used by the
-- framework, however some times useful when writing code that is shared between
-- client and server.
--
data TokPeerRole (peerRole :: PeerRole) where
TokAsClient :: TokPeerRole AsClient
TokAsServer :: TokPeerRole AsServer

-- | This data type is used to hold state tokens for states with either client
-- or server agency. This GADT shows up when writing protocol peers, when
-- 'Yield'ing or 'Await'ing, and when writing message encoders\/decoders.
Expand Down

0 comments on commit b744ede

Please sign in to comment.