# 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

## 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

## 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

\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