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: moved types to Core module
  • Loading branch information
coot committed Sep 16, 2024
commit 0d9cb7775e5cbc605ff258f43740a6a348fa26a5
43 changes: 41 additions & 2 deletions typed-protocols/src/Network/TypedProtocol/Core.hs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}
-- need for 'Show' instance of 'ProtocolState'
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}

-- | This module defines the core of the typed protocol framework.
--
Expand All @@ -43,6 +44,9 @@ module Network.TypedProtocol.Core
, IsPipelined (..)
, Outstanding
, N (..)
, Nat (Succ, Zero)
, natToInt
, unsafeIntToNat
, ActiveAgency
, ActiveAgency' (..)
, IsActiveState (..)
Expand All @@ -51,6 +55,7 @@ module Network.TypedProtocol.Core
) where

import Data.Kind (Constraint, Type)
import Unsafe.Coerce (unsafeCoerce)

import Data.Singletons

Expand Down Expand Up @@ -504,3 +509,37 @@ type Outstanding :: IsPipelined -> N
type family Outstanding pl where
Outstanding 'NonPipelined = Z
Outstanding ('Pipelined n _) = n

-- | A value level inductive natural number, indexed by the corresponding type
-- level natural number 'N'.
--
-- This is often needed when writing pipelined peers to be able to count the
-- number of outstanding pipelined yields, and show to the type checker that
-- 'SenderCollect' and 'SenderDone' are being used correctly.
--
newtype Nat (n :: N) = UnsafeInt Int
deriving Show via Int

data IsNat (n :: N) where
IsZero :: IsNat Z
IsSucc :: Nat n -> IsNat (S n)

toIsNat :: Nat n -> IsNat n
toIsNat (UnsafeInt 0) = unsafeCoerce IsZero
toIsNat (UnsafeInt n) = unsafeCoerce (IsSucc (UnsafeInt (pred n)))

pattern Zero :: () => Z ~ n => Nat n
pattern Zero <- (toIsNat -> IsZero) where
Zero = UnsafeInt 0

pattern Succ :: () => (m ~ S n) => Nat n -> Nat m
pattern Succ n <- (toIsNat -> IsSucc n) where
Succ (UnsafeInt n) = UnsafeInt (succ n)

{-# COMPLETE Zero, Succ #-}

natToInt :: Nat n -> Int
natToInt (UnsafeInt n) = n

unsafeIntToNat :: Int -> Nat n
unsafeIntToNat = UnsafeInt
37 changes: 0 additions & 37 deletions typed-protocols/src/Network/TypedProtocol/Peer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}

-- | Protocol EDSL.
--
Expand All @@ -28,7 +26,6 @@ module Network.TypedProtocol.Peer
) where

import Data.Kind (Type)
import Unsafe.Coerce (unsafeCoerce)

import Network.TypedProtocol.Core as Core

Expand Down Expand Up @@ -257,37 +254,3 @@ data Receiver ps pr st stdone m c where
-> Receiver ps pr st stdone m c

deriving instance Functor m => Functor (Receiver ps pr st stdone m)

-- | A value level inductive natural number, indexed by the corresponding type
-- level natural number 'N'.
--
-- This is often needed when writing pipelined peers to be able to count the
-- number of outstanding pipelined yields, and show to the type checker that
-- 'SenderCollect' and 'SenderDone' are being used correctly.
--
newtype Nat (n :: N) = UnsafeInt Int
deriving Show via Int

data IsNat (n :: N) where
IsZero :: IsNat Z
IsSucc :: Nat n -> IsNat (S n)

toIsNat :: Nat n -> IsNat n
toIsNat (UnsafeInt 0) = unsafeCoerce IsZero
toIsNat (UnsafeInt n) = unsafeCoerce (IsSucc (UnsafeInt (pred n)))

pattern Zero :: () => Z ~ n => Nat n
pattern Zero <- (toIsNat -> IsZero) where
Zero = UnsafeInt 0

pattern Succ :: () => (m ~ S n) => Nat n -> Nat m
pattern Succ n <- (toIsNat -> IsSucc n) where
Succ (UnsafeInt n) = UnsafeInt (succ n)

{-# COMPLETE Zero, Succ #-}

natToInt :: Nat n -> Int
natToInt (UnsafeInt n) = n

unsafeIntToNat :: Int -> Nat n
unsafeIntToNat = UnsafeInt
2 changes: 1 addition & 1 deletion typed-protocols/src/Network/TypedProtocol/Peer/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Network.TypedProtocol.Peer.Client
import Data.Kind (Type)

import Network.TypedProtocol.Core
import Network.TypedProtocol.Peer (Peer, Nat (..))
import Network.TypedProtocol.Peer (Peer)
import qualified Network.TypedProtocol.Peer as TP


Expand Down
2 changes: 1 addition & 1 deletion typed-protocols/src/Network/TypedProtocol/Peer/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Network.TypedProtocol.Peer.Server
import Data.Kind (Type)

import Network.TypedProtocol.Core
import Network.TypedProtocol.Peer (Peer, Nat (..))
import Network.TypedProtocol.Peer (Peer)
import qualified Network.TypedProtocol.Peer as TP


Expand Down