Skip to content

Commit

Permalink
typed-protocols: added StateToken type family to Protocol type class
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed Jul 25, 2024
1 parent 3bba149 commit 15dbb3c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,7 @@ instance Protocol PingPong where
type StateAgency StBusy = ServerAgency
type StateAgency StDone = NobodyAgency

type StateToken = SPingPong


deriving instance Show (Message PingPong from to)
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ instance Protocol (ReqResp req resp) where
type StateAgency StBusy = ServerAgency
type StateAgency StDone = NobodyAgency

type StateToken = SReqResp


deriving instance (Show req, Show resp)
=> Show (Message (ReqResp req resp) from to)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ instance Protocol (ReqResp2 req resp) where
type StateAgency StBusy' = ServerAgency
type StateAgency StDone = NobodyAgency

type StateToken = SReqResp2


deriving instance (Show req, Show resp)
=> Show (Message (ReqResp2 req resp) from to)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ instance Protocol (Wedge ps (stIdle :: ps) ps' (stIdle' :: ps')) where
type StateAgency (StFst st) = StateAgency st
type StateAgency (StSnd st) = StateAgency st

type StateToken = SingWedge


type PingPong2 = Wedge PingPong.PingPong PingPong.StIdle
PingPong.PingPong PingPong.StIdle
Expand Down
12 changes: 12 additions & 0 deletions typed-protocols/src/Network/TypedProtocol/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ module Network.TypedProtocol.Core
, IsActiveState (..)
, ActiveState
, notActiveState
-- * Utils
, stateToken
) where

import Data.Kind (Constraint, Type)
Expand Down Expand Up @@ -404,6 +406,16 @@ class Protocol ps where
--
type StateAgency (st :: ps) :: Agency

-- | A type alias for protocol state token, e.g. term level representation of
-- type level state (also known as singleton).
--
type StateToken :: ps -> Type

-- | An alias for 'sing'.
--
stateToken :: (SingI st, Sing st ~ StateToken st) => StateToken st
stateToken = sing

type ActiveAgency' :: ps -> Agency -> Type
data ActiveAgency' st agency where
ClientHasAgency :: StateAgency st ~ ClientAgency
Expand Down

0 comments on commit 15dbb3c

Please sign in to comment.