Skip to content

Commit 93a2b34

Browse files
committed
Updated typed-protocols-doc-demo
1 parent 9843f86 commit 93a2b34

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

typed-protocols-doc/demo/DemoProtocol.hs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@
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+
1519
module DemoProtocol
1620
where
1721

18-
import Network.TypedProtocol.Core
19-
import Data.SerDoc.Info
2022
import Control.Monad.Identity
2123
import Control.Monad.Except
24+
2225
import Data.Proxy
23-
import Data.Word
24-
import Data.Typeable
2526
import Data.SerDoc.Class
27+
import Data.SerDoc.Info
2628
import Data.SerDoc.TH
2729
import Data.Text (Text)
30+
import Data.Word
31+
32+
import Network.TypedProtocol.Core
2833

2934
data 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+
4761
instance 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

7676
data DemoCodec a
7777

typed-protocols-doc/src/Network/TypedProtocol/Documentation/DefaultMain.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ pMainOptions =
6565
)
6666

6767

68-
defaultMain :: ( Codec codec
69-
, HasInfo codec (DefEnumEncoding codec)
68+
defaultMain :: ( HasInfo codec (DefEnumEncoding codec)
7069
, HasInfo codec Word32
7170
) => [ProtocolDescription codec] -> IO ()
7271
defaultMain descriptions = do
@@ -79,8 +78,7 @@ defaultMain descriptions = do
7978
render = getRenderer (moOutputFormat mainOptions) (moOutputFile mainOptions)
8079
write . render $ descriptions
8180

82-
getRenderer :: ( Codec codec
83-
, HasInfo codec (DefEnumEncoding codec)
81+
getRenderer :: ( HasInfo codec (DefEnumEncoding codec)
8482
, HasInfo codec Word32
8583
)
8684
=> OutputFormat

typed-protocols-doc/test/Network/TypedProtocol/Tests/TestProtocol.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import Control.Monad.Identity
2323
import Control.Monad.Except
2424
import Data.Proxy
2525
import Data.Word
26-
import Data.Typeable
2726
import Data.SerDoc.Class
2827
import Data.SerDoc.TH
2928
import Data.Text (Text)

0 commit comments

Comments
 (0)