Evaluating Linear Functions to Symmetric Monoidal Categories
Jean-Philippe Bernardy & Arnaud Spiwack
Box-and-wires diagrams
- (Quantum) circuits
- Workflow orchestration
- Bayesian networks
- Sequence diagrams
- Map/reduce graphs Γ la Spark
- β¦
Motivation: limits of Arrow
(π *** π) >>>
arr (\((x,y),z) -> (x,(y,z))) >>>
(π *** π)
first π >>>
((first π) *** π) >>>
arr (\((x,y),z) -> (x,(y,z))) >>>
π
Parellism (or lack thereof)
(π *** π) >>>
arr (\((x,y),z) -> (x,(y,z))) >>>
(π *** π)
first π >>>
((first π) *** π) >>>
arr (\((x,y),z) -> (x,(y,z))) >>>
π
1
2
1
3
2
1
2
1
2
3
SMCs
class Category k => SymmetricMonoidal k where
(Γ) :: (a `k` b) -> (c `k` d) -> (a β c) `k` (b β d)
π :: (a β b) `k` (b β a)
πΌ :: ((a β b) β c) `k` (a β (b β c))
πΌΒ―ΒΉ :: (a β (b β c)) `k` ((a β b) β c)
π :: a `k` (a β ())
πΒ―ΒΉ :: (a β ()) `k` a
SMCs
Arrows vs SMCs
A \otimes (B \otimes C) \longrightarrow C \otimes (A \otimes B)
\alpha \circ (\sigma \times \mathsf{id}) \circ \alpha^{-1} \circ (\mathsf{id}\times \sigma)
SMC
Arrow
\mathsf{arr} (\lambda (a,(b,c)) \rightarrow (c,(a,b)))
Linear types
(a \multimap b)
Linear types Β Β Β SMC
\approx
An idea (we didn't pursue)
What we did
let f (a,b) =
let (x,y,z) = π a in
let (t,w) = π (y,b) in
(π (x,t), π (z,w))
in
decode f
Ports
\phi
A port
Ports
\phi
π :: (P a, P b) βΈ (P c, P d, P e)
Ports as a library
type P :: (Type -> Type -> Type) -> Type -> Type -> Type
unit :: P k r ()
split :: P k r (a β b) βΈ (P k r a, P k r b)
merge :: (P k r a , P k r b) βΈ P k r (a β b)
encode :: (a `k` b) -> (P k r a βΈ P k r b)
decode :: (forall r. P k r a βΈ P k r b) -> (a `k` b)
the category
technical device
must be linear
Ports in theory
\phi
Ports βliveβ in a syntactic cartesian extension
Linear types ensure that we can eliminate the cartesian syntax
Parallelism restored
proc (a,b) -> do
(x,y) <- π -< a
z <- π -< b
c <- π -< x
d <- π -< (y,z)
returnA -< (c,d)
\(a,b) ->
let (x,y) = π a in
let z = π b in
let c = π x in
let d = π (y,z) in
(c,d)
Arrow
SMC
https://slides.com/aspiwack/haskell-symposium-2021
https://hackage.haskell.org/package/linear-smc
https://dl.acm.org/doi/10.1145/3471874.3472980
Evaluating Linear Functions to Symmetric Monoidal Categories
By Arnaud Spiwack
Evaluating Linear Functions to Symmetric Monoidal Categories
- 620