File tree Expand file tree Collapse file tree 5 files changed +20
-0
lines changed
typed-protocols-examples/src/Network/TypedProtocol
typed-protocols/src/Network/TypedProtocol Expand file tree Collapse file tree 5 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -76,5 +76,7 @@ instance Protocol PingPong where
7676 type StateAgency StBusy = ServerAgency
7777 type StateAgency StDone = NobodyAgency
7878
79+ type StateToken = SPingPong
80+
7981
8082deriving instance Show (Message PingPong from to )
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ instance Protocol (ReqResp req resp) where
4646 type StateAgency StBusy = ServerAgency
4747 type StateAgency StDone = NobodyAgency
4848
49+ type StateToken = SReqResp
50+
4951
5052deriving instance (Show req , Show resp )
5153 => Show (Message (ReqResp req resp ) from to )
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ instance Protocol (ReqResp2 req resp) where
5555 type StateAgency StBusy' = ServerAgency
5656 type StateAgency StDone = NobodyAgency
5757
58+ type StateToken = SReqResp2
59+
5860
5961deriving instance (Show req , Show resp )
6062 => Show (Message (ReqResp2 req resp ) from to )
Original file line number Diff line number Diff line change @@ -105,6 +105,8 @@ instance Protocol (Wedge ps (stIdle :: ps) ps' (stIdle' :: ps')) where
105105 type StateAgency (StFst st ) = StateAgency st
106106 type StateAgency (StSnd st ) = StateAgency st
107107
108+ type StateToken = SingWedge
109+
108110
109111type PingPong2 = Wedge PingPong. PingPong PingPong. StIdle
110112 PingPong. PingPong PingPong. StIdle
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ module Network.TypedProtocol.Core
4747 , IsActiveState (.. )
4848 , ActiveState
4949 , notActiveState
50+ -- * Utils
51+ , stateToken
5052 ) where
5153
5254import Data.Kind (Constraint , Type )
@@ -402,6 +404,16 @@ class Protocol ps where
402404 --
403405 type StateAgency (st :: ps ) :: Agency
404406
407+ -- | A type alias for protocol state token, e.g. term level representation of
408+ -- type level state (also known as singleton).
409+ --
410+ type StateToken :: ps -> Type
411+
412+ -- | An alias for 'sing'.
413+ --
414+ stateToken :: (SingI st , Sing st ~ StateToken st ) => StateToken st
415+ stateToken = sing
416+
405417type ActiveAgency' :: ps -> Agency -> Type
406418data ActiveAgency' st agency where
407419 ClientHasAgency :: StateAgency st ~ ClientAgency
You can’t perform that action at this time.
0 commit comments