55{-# LANGUAGE FlexibleInstances #-}
66{-# LANGUAGE GADTs #-}
77{-# LANGUAGE MultiParamTypeClasses #-}
8+ {-# LANGUAGE PolyKinds #-}
89{-# LANGUAGE StandaloneDeriving #-}
910{-# LANGUAGE TypeApplications #-}
1011{-# LANGUAGE TypeFamilies #-}
1112{-# LANGUAGE UndecidableInstances #-}
1213{-# LANGUAGE ScopedTypeVariables #-}
1314{-# LANGUAGE TemplateHaskell #-}
1415
16+ -- for `deriveSerDoc`
17+ {-# OPTIONS_GHC -Wno-redundant-constraints #-}
18+
1519module DemoProtocol
1620where
1721
18- import Network.TypedProtocol.Core
19- import Data.SerDoc.Info
2022import Control.Monad.Identity
2123import Control.Monad.Except
24+
2225import Data.Proxy
23- import Data.Word
24- import Data.Typeable
2526import Data.SerDoc.Class
27+ import Data.SerDoc.Info
2628import Data.SerDoc.TH
2729import Data.Text (Text )
30+ import Data.Word
31+
32+ import Network.TypedProtocol.Core
2833
2934data PongInfo =
3035 PongInfo
@@ -44,34 +49,29 @@ data DemoProtocol a where
4449 -- | End state: either side has terminated the session
4550 EndState :: DemoProtocol a
4651
52+ data SingDemoProtocol a where
53+ SingIdleState :: SingDemoProtocol (IdleState :: DemoProtocol a )
54+ SingAwaitingPongState :: SingDemoProtocol (AwaitingPongState :: DemoProtocol a )
55+ SingEndState :: SingDemoProtocol (EndState :: DemoProtocol a )
56+
57+ instance StateTokenI IdleState where stateToken = SingIdleState
58+ instance StateTokenI AwaitingPongState where stateToken = SingAwaitingPongState
59+ instance StateTokenI EndState where stateToken = SingEndState
60+
4761instance Protocol (DemoProtocol a ) where
4862 data Message (DemoProtocol a ) st st' where
4963 PingMessage :: Message (DemoProtocol a ) IdleState AwaitingPongState
5064 PongMessage :: Message (DemoProtocol a ) AwaitingPongState IdleState
5165 ComplexPongMessage :: Message (DemoProtocol a ) AwaitingPongState IdleState
5266 EndMessage :: Message (DemoProtocol a ) st EndState
5367
54- data ServerHasAgency st where
55- TokIdle :: ServerHasAgency IdleState
56-
57- data ClientHasAgency st where
58- TokAwaitingPongState :: ClientHasAgency AwaitingPongState
59-
60- data NobodyHasAgency st where
61- TokEnd :: NobodyHasAgency EndState
62-
68+ type StateAgency IdleState = ServerAgency
69+ type StateAgency AwaitingPongState = ClientAgency
70+ type StateAgency EndState = NobodyAgency
6371
64- exclusionLemma_ClientAndServerHaveAgency tok1 tok2 =
65- case tok1 of
66- TokAwaitingPongState -> case tok2 of {}
72+ type StateToken = SingDemoProtocol
6773
68- exclusionLemma_NobodyAndClientHaveAgency tok1 tok2 =
69- case tok1 of
70- TokEnd -> case tok2 of {}
7174
72- exclusionLemma_NobodyAndServerHaveAgency tok1 tok2 =
73- case tok1 of
74- TokEnd -> case tok2 of {}
7575
7676data DemoCodec a
7777
0 commit comments