Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
08ee7c4
typed-protocols: new API
coot Jul 25, 2024
81f2fbe
typed-protocols: Peer pattern synonyms
coot Jul 25, 2024
fe36759
typed-protocols-examples: updated
coot Jul 25, 2024
88d246f
typed-protocols: ActiveAgency
coot Sep 6, 2021
b121a80
typed-protocols: simplify runPeerWithDriver
coot Mar 27, 2022
bdf8100
typed-protocols: internal lemmas module
coot May 23, 2022
564da48
typed-protocols: provide ReflRelativeAgency type aliases
coot Jul 13, 2022
6f5ce41
typed-protocols-examples: socketAsChannel
coot Sep 4, 2021
c69993a
typed-protocols-examples: ReqResp2 example
coot Sep 17, 2021
e4bcf98
typed-protocols-examples: Wedge
coot Sep 18, 2021
86d007a
typed-protocols-examples: requestOnce
coot Sep 28, 2021
b4070d4
typed-protocols-examples: fixed cborg tests
coot Oct 2, 2021
74a64f2
typed-protocols-examples: pipelined tests
coot Oct 2, 2021
5ef5f2d
typed-protocols-examples: unbounded buffered channel
coot Mar 27, 2022
ce833a9
typed-protocols-examples: added runConnectedPeersAsymetric
coot Mar 27, 2022
1ca4aa7
typed-protocols: simplify evidence of termination in a terminal state
coot May 13, 2022
558a9fc
typed-protocols: added StateToken type family to Protocol type class
coot Jun 23, 2022
03270e4
typed-protocols: renamed Pipelined kind to IsPipelined
coot Jul 13, 2022
6b6118d
typed-protocols: added AnyMessageAndAgency pattern synonym
coot Sep 8, 2023
abecdaf
typed-protocols: added application specific singletons for protocol s…
coot Sep 26, 2023
a81caa1
typed-protocols-examples: relaxed constraint in PingPong client
coot Jul 1, 2022
166f5af
typed-protocols-examples: fixed a socket test on macos
coot Aug 17, 2022
f5ccedd
typed-protocols: bump version to `0.2.0.0`
coot Aug 25, 2023
148a91b
Added CHANGELOG and bumped versions of the packages
coot May 17, 2022
6c6a8ce
typed-protocols: moved outstanding counter into IsPipelined kind
coot Jul 23, 2024
d2f1e74
typed-protocols-stateful: non-pipelined stateful Peer
coot Jul 24, 2024
0d9cb77
typed-protocols: moved types to `Core` module
coot Jul 24, 2024
5ec9a8c
typed-protocols: connectPipelined type signature
coot Jul 24, 2024
8d31814
typed-protocols: added PeerPipelined newtype wrapper
coot Jul 24, 2024
b3ba779
Support io-classes-1.7
coot Jul 26, 2024
b23f327
typed-protocols: added haddocks
coot Aug 19, 2024
72a799c
disabled `typed-protocols-doc` in GHA
coot Aug 22, 2024
5cf79f3
stylish-haskell: fixes
coot Aug 22, 2024
b9e71bb
typed-protocols: removed unused extensions
coot Aug 23, 2024
20aa2fe
Improved haddocks, removed unused pragmas (extensions)
coot Aug 23, 2024
bdcf30a
Core module cannot be checked with stylish-haskell
coot Aug 23, 2024
0042b72
Removed Stateful PingPong example
coot Sep 4, 2024
b195c92
Stateful RPC example
coot Sep 5, 2024
f451040
typed-protocols: fixed typos
coot Sep 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
typed-protocols: added application specific singletons for protocol s…
…tates

We still have `singletons` as a dependency though.
  • Loading branch information
coot committed Sep 16, 2024
commit abecdaf63ab8342d43170c5504eb60a67d604d61
9 changes: 4 additions & 5 deletions typed-protocols-cborg/src/Network/TypedProtocol/Codec/CBOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import qualified Data.ByteString.Builder as BS
import qualified Data.ByteString.Builder.Extra as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Lazy.Internal as LBS (smallChunkSize)
import Data.Singletons

import Network.TypedProtocol.Codec
import Network.TypedProtocol.Core
Expand All @@ -48,13 +47,13 @@ mkCodecCborStrictBS
:: forall ps m. MonadST m

=> (forall (st :: ps) (st' :: ps).
SingI st
StateTokenI st
=> ActiveState st
=> Message ps st st' -> CBOR.Encoding)

-> (forall (st :: ps) s.
ActiveState st
=> Sing st
=> StateToken st
-> CBOR.Decoder s (SomeMessage st))

-> Codec ps DeserialiseFailure m BS.ByteString
Expand Down Expand Up @@ -104,13 +103,13 @@ mkCodecCborLazyBS
:: forall ps m. MonadST m

=> (forall (st :: ps) (st' :: ps).
SingI st
StateTokenI st
=> ActiveState st
=> Message ps st st' -> CBOR.Encoding)

-> (forall (st :: ps) s.
ActiveState st
=> Sing st
=> StateToken st
-> CBOR.Decoder s (SomeMessage st))

-> Codec ps CBOR.DeserialiseFailure m LBS.ByteString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ module Network.TypedProtocol.Driver.Simple
, runDecoderWithChannel
) where

import Data.Singletons

import Network.TypedProtocol.Channel
import Network.TypedProtocol.Codec
import Network.TypedProtocol.Core
Expand Down Expand Up @@ -91,7 +89,7 @@ driverSimple tracer Codec{encode, decode} channel@Channel{send} =
Driver { sendMessage, recvMessage, initialDState = Nothing }
where
sendMessage :: forall (st :: ps) (st' :: ps).
( SingI st
( StateTokenI st
, ActiveState st
)
=> ReflRelativeAgency (StateAgency st)
Expand All @@ -104,7 +102,7 @@ driverSimple tracer Codec{encode, decode} channel@Channel{send} =
traceWith tracer (TraceSendMsg (AnyMessage msg))

recvMessage :: forall (st :: ps).
( SingI st
( StateTokenI st
, ActiveState st
)
=> ReflRelativeAgency (StateAgency st)
Expand All @@ -113,7 +111,7 @@ driverSimple tracer Codec{encode, decode} channel@Channel{send} =
-> Maybe bytes
-> m (SomeMessage st, Maybe bytes)
recvMessage !_refl trailing = do
decoder <- decode sing
decoder <- decode stateToken
result <- runDecoderWithChannel channel trailing decoder
case result of
Right x@(SomeMessage msg, _trailing') -> do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

module Network.TypedProtocol.PingPong.Codec where

import Data.Singletons

import Network.TypedProtocol.Codec
import Network.TypedProtocol.Core
import Network.TypedProtocol.PingPong.Type
Expand All @@ -29,7 +27,7 @@ codecPingPong =

decode :: forall (st :: PingPong).
ActiveState st
=> Sing st
=> StateToken st
-> m (DecodeStep String CodecFailure m (SomeMessage st))
decode stok =
decodeTerminatedFrame '\n' $ \str trailing ->
Expand Down Expand Up @@ -72,7 +70,7 @@ codecPingPongId =
Codec{encode,decode}
where
encode :: forall (st :: PingPong) (st' :: PingPong)
. ( SingI st
. ( StateTokenI st
, ActiveState st
)
=> Message PingPong st st'
Expand All @@ -81,7 +79,7 @@ codecPingPongId =

decode :: forall (st :: PingPong).
ActiveState st
=> Sing st
=> StateToken st
-> m (DecodeStep (AnyMessage PingPong) CodecFailure m (SomeMessage st))
decode stok =
pure $ DecodePartial $ \mb ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Network.TypedProtocol.PingPong.Codec.CBOR where
import Control.Monad.Class.MonadST

import Data.ByteString.Lazy (ByteString)
import Data.Singletons

import qualified Codec.CBOR.Decoding as CBOR (Decoder, decodeWord)
import qualified Codec.CBOR.Encoding as CBOR (Encoding, encodeWord)
Expand All @@ -36,7 +35,7 @@ codecPingPong = mkCodecCborLazyBS encodeMsg decodeMsg

decodeMsg :: forall s (st :: PingPong).
ActiveState st
=> Sing st
=> StateToken st
-> CBOR.Decoder s (SomeMessage st)
decodeMsg stok = do
key <- CBOR.decodeWord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

module Network.TypedProtocol.PingPong.Type where

import Data.Singletons

import Network.TypedProtocol.Core


Expand Down Expand Up @@ -44,14 +42,12 @@ data SPingPong (st :: PingPong) where

deriving instance Show (SPingPong st)

type instance Sing = SPingPong
instance SingI StIdle where
sing = SingIdle
instance SingI StBusy where
sing = SingBusy
instance SingI StDone where
sing = SingDone

instance StateTokenI StIdle where
stateToken = SingIdle
instance StateTokenI StBusy where
stateToken = SingBusy
instance StateTokenI StDone where
stateToken = SingDone

instance Protocol PingPong where

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

module Network.TypedProtocol.ReqResp.Codec where

import Data.Singletons

import Network.TypedProtocol.Codec
import Network.TypedProtocol.Core
import Network.TypedProtocol.PingPong.Codec (decodeTerminatedFrame)
Expand All @@ -35,7 +33,7 @@ codecReqResp =
decode :: forall req' resp' m'
(st :: ReqResp req' resp')
. (Monad m', Read req', Read resp', ActiveState st)
=> Sing st
=> StateToken st
-> m' (DecodeStep String CodecFailure m' (SomeMessage st))
decode stok =
decodeTerminatedFrame '\n' $ \str trailing ->
Expand All @@ -62,15 +60,15 @@ codecReqRespId =
where
encode :: forall (st :: ReqResp req resp)
(st' :: ReqResp req resp)
. SingI st
. StateTokenI st
=> ActiveState st
=> Message (ReqResp req resp) st st'
-> AnyMessage (ReqResp req resp)
encode msg = AnyMessage msg

decode :: forall (st :: ReqResp req resp)
. ActiveState st
=> Sing st
=> StateToken st
-> m (DecodeStep (AnyMessage (ReqResp req resp)) CodecFailure m (SomeMessage st))
decode stok =
pure $ DecodePartial $ \mb ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Network.TypedProtocol.ReqResp.Codec.CBOR where
import Control.Monad.Class.MonadST

import Data.ByteString.Lazy (ByteString)
import Data.Singletons

import qualified Codec.CBOR.Decoding as CBOR (Decoder, decodeListLen,
decodeWord)
Expand Down Expand Up @@ -46,7 +45,7 @@ codecReqResp = mkCodecCborLazyBS encodeMsg decodeMsg

decodeMsg :: forall s (st :: ReqResp req resp).
ActiveState st
=> Sing st
=> StateToken st
-> CBOR.Decoder s (SomeMessage st)
decodeMsg stok = do
_ <- CBOR.decodeListLen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

module Network.TypedProtocol.ReqResp.Type where

import Data.Singletons

import Network.TypedProtocol.Core


Expand All @@ -26,13 +24,12 @@ data SReqResp (st :: ReqResp req resp) where

deriving instance Show (SReqResp st)

type instance Sing = SReqResp
instance SingI StIdle where
sing = SingIdle
instance SingI StBusy where
sing = SingBusy
instance SingI StDone where
sing = SingDone
instance StateTokenI StIdle where
stateToken = SingIdle
instance StateTokenI StBusy where
stateToken = SingBusy
instance StateTokenI StDone where
stateToken = SingDone


instance Protocol (ReqResp req resp) where
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

module Network.TypedProtocol.ReqResp2.Type where

import Data.Singletons

import Network.TypedProtocol.Core


Expand All @@ -28,15 +26,14 @@ data SReqResp2 (st :: ReqResp2 req resp) where

deriving instance Show (SReqResp2 st)

type instance Sing = SReqResp2
instance SingI StIdle where
sing = SingIdle
instance SingI StBusy where
sing = SingBusy
instance SingI StBusy' where
sing = SingBusy'
instance SingI StDone where
sing = SingDone
instance StateTokenI StIdle where
stateToken = SingIdle
instance StateTokenI StBusy where
stateToken = SingBusy
instance StateTokenI StBusy' where
stateToken = SingBusy'
instance StateTokenI StDone where
stateToken = SingDone


instance Protocol (ReqResp2 req resp) where
Expand Down
23 changes: 10 additions & 13 deletions typed-protocols-examples/src/Network/TypedProtocol/Trans/Wedge.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

module Network.TypedProtocol.Trans.Wedge where

import Data.Singletons

import Network.TypedProtocol.Core

import qualified Network.TypedProtocol.Peer.Client as Client
Expand All @@ -37,25 +35,24 @@ data Wedge ps (stIdle :: ps) ps' (stIdle' :: ps') where

data SingWedge (st :: Wedge ps (stIdle :: ps) ps' (stIdle' :: ps')) where
SingStIdle :: SingWedge StIdle
SingStFst :: Sing st
SingStFst :: StateToken st
-> SingWedge (StFst st)
SingStSnd :: Sing st'
SingStSnd :: StateToken st'
-> SingWedge (StSnd st')

instance Show (SingWedge StIdle) where
show SingStIdle = "SingStIdle"
instance Show (Sing st) => Show (SingWedge (StFst st)) where
instance Show (StateToken st) => Show (SingWedge (StFst st)) where
show (SingStFst s) = "SingStFst " ++ show s
instance Show (Sing st) => Show (SingWedge (StSnd st)) where
instance Show (StateToken st) => Show (SingWedge (StSnd st)) where
show (SingStSnd s) = "SingStSnd " ++ show s

type instance Sing = SingWedge
instance SingI StIdle where
sing = SingStIdle
instance SingI st => SingI (StFst st) where
sing = SingStFst (sing @st)
instance SingI st => SingI (StSnd st) where
sing = SingStSnd (sing @st)
instance StateTokenI StIdle where
stateToken = SingStIdle
instance StateTokenI st => StateTokenI (StFst st) where
stateToken = SingStFst (stateToken @st)
instance StateTokenI st => StateTokenI (StSnd st) where
stateToken = SingStSnd (stateToken @st)


-- | A Singleton type which allows to pick the starting protocol state.
Expand Down
Loading