Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Process s a = Process {
- getProcess :: IO a
- data Chan n = forall a . MkChan (Chan a)
- data Name
- data Symbol :: *
- data Session
- data Delegate = Delg Session
- type family Dual s
- type family DualP s t :: Constraint
- type family SessionSeq s t
- type family Balanced s t :: Constraint
- type family NotBal s :: Constraint
- class Effect m where
- fail :: t
- run :: Process [] a -> IO a
- data Map k v = k :-> v
- type family m :@ c :: Session
- type Union m n = Nub (Sort (m :++ n))
- type family m :\ c :: [Map k v]
- send :: Chan c -> t -> Process `[c :-> (t :! End)]` ()
- recv :: Chan c -> Process `[c :-> (t :? End)]` t
- new :: Duality env c => ((Chan (Ch c), Chan (Op c)) -> Process env t) -> Process ((env :\ Op c) :\ Ch c) t
- par :: Balanced env (AllBal env') => Process env () -> Process env' () -> Process (Union env env') ()
- rsend :: Chan c -> Chan d -> Process `[c :-> (Delg s :*! End), d :-> Bal s]` ()
- chSend :: Chan c -> Chan d -> Process `[c :-> (Delg s :! End), d :-> Bal s]` ()
- chRecv :: Chan c -> (Chan d -> Process env a) -> Process (Union `[c :-> (Delg (env :@ d) :? (env :@ c))]` (env :\ d)) a
- sub :: Subeffect m f g => m f a -> m g a
- subL :: Process `[c :-> s]` a -> Process `[c :-> (s :+ t)]` a
- subR :: Process `[c :-> t]` a -> Process `[c :-> (s :+ t)]` a
- subEnd :: Chan c -> Process [] a -> Process `[c :-> End]` a
- affineFix :: ((a -> Process `[c :-> Star]` b) -> a -> Process `[c :-> h]` b) -> a -> Process `[c :-> ToFix h]` b
- print :: Show a => a -> Process [] ()
- putStrLn :: String -> Process ([] (Map Name Session)) ()
- liftIO :: IO a -> Process [] a
- ifThenElse :: Bool -> t -> t -> t
Documentation
Process computation type indexed by an environment of the (free) channel names used in the computation, paired with a specification of their behaviour.
Process | |
|
Namec channels, encapsulating Concurrent Haskell channels
Channel endpoint names
Effect [Map Name Session] Process Source | |
type Unit [Map Name Session] Process = [] (Map Name Session) Source | |
type Plus [Map Name Session] Process s t = Union Name Session s t Source | |
type Inv [Map Name Session] Process s t = Balanced s t Source | |
type Cmp (Map Name Session) ((:->) Name Session c a) ((:->) Name Session d b) = CmpSessionMap ((:->) Name Session c a) ((:->) Name Session d b) Source | Compare channel names for normalising type-level finite map representations |
Session types
forall a . a :! Session | Send |
forall a . a :? Session | Receive |
forall a . a :*! Session | Output |
Session :+ Session | Alternation (for branch/select) |
Bal Session | Marks a session that should |
End | End of session |
Fix Session Session | Denotes an affine fixed point, where Fix a b = a* . b |
Star | A placeholder for a recursion variable- never generated by
the encoding or produced by any operation, but set as
the session type for a recursive call in a fixed-point (see |
Effect [Map Name Session] Process Source | |
type Combine Session s t = SessionSeq s t Source | |
type Unit [Map Name Session] Process = [] (Map Name Session) Source | |
type Plus [Map Name Session] Process s t = Union Name Session s t Source | |
type Inv [Map Name Session] Process s t = Balanced s t Source | |
type Cmp (Map Name Session) ((:->) Name Session c a) ((:->) Name Session d b) = CmpSessionMap ((:->) Name Session c a) ((:->) Name Session d b) Source | Compare channel names for normalising type-level finite map representations |
Duality function: calculuate the dual of a simple, non-recursive session type
type family DualP s t :: Constraint Source
Duality relation: extends the duality function to include recursive session types
DualP End End = () | |
DualP (t :! s) (t' :? s') = (t ~ t', DualP s s') | |
DualP (t :? s) (t' :! s') = (t ~ t', DualP s s') | |
DualP (Bal s) s' = DualP s s' | |
DualP s (Bal s') = DualP s s' | |
DualP (s :+ t) (s' :+ t') = (DualP s s', DualP t t') | |
DualP (Fix a b) s = EqFix a (Fix a b) (Dual s) | |
DualP s (Fix a b) = EqFix a (Fix a b) (Dual s) |
type family SessionSeq s t Source
Sequential composition of sessions
SessionSeq End (Bal s) = s | |
SessionSeq End s = s | |
SessionSeq (a :? s) t = a :? SessionSeq s t | |
SessionSeq (a :! s) t = a :! SessionSeq s t | |
SessionSeq (a :*! s) t = a :*! SessionSeq s t | |
SessionSeq (s1 :+ s2) t = SessionSeq s1 t :+ SessionSeq s2 t | |
SessionSeq (Bal s) t = SessionSeq s t | |
SessionSeq Star Star = Star |
type family Balanced s t :: Constraint Source
Predicate for checking that two environments are balanced
type family NotBal s :: Constraint Source
Checks that we are not requiring a balanced session
Specifies "parametric effect monads" which are essentially monads but
annotated by a type-level monoid formed by Plus
and Unit
Effect of a trivially effectful computation |
Cominbing effects of two subcomputations |
type Inv m f g :: Constraint Source
return :: a -> m (Unit m) a Source
Effect-parameterised version of return
. Annotated with the 'Unit m' effect,
denoting pure compuation
(>>=) :: Inv m f g => m f a -> (a -> m g b) -> m (Plus m f g) b Source
Effect-parameterise version of >>=
(bind). Combines
two effect annotations f
and g
on its parameter computations into Plus
(>>) :: Inv m f g => m f a -> m g b -> m (Plus m f g) b Source
run :: Process [] a -> IO a Source
A process can be run if it is closed (i.e., empty channel environment)
k :-> v infixr 4 |
Effect [Map Name Session] Process Source | |
type Unit [Map Name Session] Process = [] (Map Name Session) Source | |
type Plus [Map Name Session] Process s t = Union Name Session s t Source | |
type Inv [Map Name Session] Process s t = Balanced s t Source | |
type Cmp (Map Name Session) ((:->) Name Session c a) ((:->) Name Session d b) = CmpSessionMap ((:->) Name Session c a) ((:->) Name Session d b) Source | Compare channel names for normalising type-level finite map representations |
type family m :@ c :: Session Source
Lookup a channel from an enrivonment, returning End
if it is not a member
new :: Duality env c => ((Chan (Ch c), Chan (Op c)) -> Process env t) -> Process ((env :\ Op c) :\ Ch c) t Source
Create a new channel and pass its two endpoints to the supplied continuation (the first parameter). This channel is thus only in scope for this continuation
par :: Balanced env (AllBal env') => Process env () -> Process env' () -> Process (Union env env') () Source
Parallel compose two processes, if they contain disjoint (or balanced) sessions
rsend :: Chan c -> Chan d -> Process `[c :-> (Delg s :*! End), d :-> Bal s]` () Source
Output a channel (dual to a replicated input)
chSend :: Chan c -> Chan d -> Process `[c :-> (Delg s :! End), d :-> Bal s]` () Source
Send a channel d
over channel c
chRecv :: Chan c -> (Chan d -> Process env a) -> Process (Union `[c :-> (Delg (env :@ d) :? (env :@ c))]` (env :\ d)) a Source
Receive a channel over a channel c
, bind to the name d
subL :: Process `[c :-> s]` a -> Process `[c :-> (s :+ t)]` a Source
Explicit subeffecting introduction of :+
with the current session behaviour on the left
subR :: Process `[c :-> t]` a -> Process `[c :-> (s :+ t)]` a Source
Explicit subeffecting introduction of :+
with the current session behaviour on the right
subEnd :: Chan c -> Process [] a -> Process `[c :-> End]` a Source
Explicit subeffecting introduction of a terminated session for channel c
affineFix :: ((a -> Process `[c :-> Star]` b) -> a -> Process `[c :-> h]` b) -> a -> Process `[c :-> ToFix h]` b Source
Recursion combinator for recursive functions which have an affine fixed-point equation on their effects. For example, if 'h ~ (Seq h a) :+ b' then 'ToFix h = Fix a b'
ifThenElse :: Bool -> t -> t -> t Source