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

Made with Slides.com