### Dan Piponi

Shared publicly -In many programming languages, including Haskell, you can freely copy values. For example, in Haskell you can write

let b = a in ...

Haskell is based on the internal language of Cartesian closed categories (CCCs). The feature of these that allows us to copy values is the fact that a CCC has a diagonal morphism

Δ:A →A×A

You can imagine making the copy more explicit by thinking of the above notation as shorthand for

let (a,b) = Δ(a) in ...

The shorthand makes clear that in some sense we're reusing the variable

If you're writing code for linear algebra it's natural to think in terms of operations in the category of vector spaces. They are equipped with a copy morphism too:

Δ:V→V⊕V

and so a vector space language should have a

But vector spaces also come equipped with a duality operation so any linear map f:A→B gives rise to another f*:B*→A*, usually called the adjoint or transpose of f. So we'd like to have

Δ*:V*⊕V*→V*

This map is more commonly known as

As I mentioned on G+ recently [2], you can construct adjoints of computer programs by a process that involves writing your code backwards. It'd be nice to have your programming language reflect this. So what operation is dual to "let b = a"? In C it'd be written

a += b

Because

In CCCs you don't have a dual to Δ so it makes sense that Haskell outlaws these kinds of mutable updates. But in a language (or DSL) for linear algebra, += is as natural a statement as

The is a simpler formulation of something I mentioned many years ago. [3]

This also serves as a reply to Twan van Laarhoven [4]. Curiously, since then Laarhoven has played an important role in making a serviceable form of += available in Haskell [5].

[1] https://golem.ph.utexas.edu/category/2006/08/cartesian_closed_categories_an_1.html

[2] https://plus.google.com/+DanPiponi/posts/9uWDCeLPLpz

[3] http://blog.sigfpe.com/2007/01/monads-hidden-behind-every-zipper.html

[4] http://blog.sigfpe.com/2008/09/two-papers-and-presentation.html

[5] http://www.twanvl.nl/files/lenses-talk-2011-05-17.pdf

let b = a in ...

Haskell is based on the internal language of Cartesian closed categories (CCCs). The feature of these that allows us to copy values is the fact that a CCC has a diagonal morphism

Δ:A →A×A

You can imagine making the copy more explicit by thinking of the above notation as shorthand for

let (a,b) = Δ(a) in ...

The shorthand makes clear that in some sense we're reusing the variable

*a*to continue labelling one of the copies. But that doesn't matter here because*a*has the same value before and after.If you're writing code for linear algebra it's natural to think in terms of operations in the category of vector spaces. They are equipped with a copy morphism too:

Δ:V→V⊕V

and so a vector space language should have a

*let*clause to allow this.But vector spaces also come equipped with a duality operation so any linear map f:A→B gives rise to another f*:B*→A*, usually called the adjoint or transpose of f. So we'd like to have

Δ*:V*⊕V*→V*

This map is more commonly known as

*addition*.As I mentioned on G+ recently [2], you can construct adjoints of computer programs by a process that involves writing your code backwards. It'd be nice to have your programming language reflect this. So what operation is dual to "let b = a"? In C it'd be written

a += b

Because

*let*is shorthand for reusing the variable name for one of the copies, the adjoint version also has a variable reuse. But this time*a*changes value so the corresponding operation is a mutation.In CCCs you don't have a dual to Δ so it makes sense that Haskell outlaws these kinds of mutable updates. But in a language (or DSL) for linear algebra, += is as natural a statement as

*let*.The is a simpler formulation of something I mentioned many years ago. [3]

This also serves as a reply to Twan van Laarhoven [4]. Curiously, since then Laarhoven has played an important role in making a serviceable form of += available in Haskell [5].

[1] https://golem.ph.utexas.edu/category/2006/08/cartesian_closed_categories_an_1.html

[2] https://plus.google.com/+DanPiponi/posts/9uWDCeLPLpz

[3] http://blog.sigfpe.com/2007/01/monads-hidden-behind-every-zipper.html

[4] http://blog.sigfpe.com/2008/09/two-papers-and-presentation.html

[5] http://www.twanvl.nl/files/lenses-talk-2011-05-17.pdf

25

7

22 comments

Should the * be a dagger?

http://ncatlab.org/nlab/show/dagger-compact+category I've seen automatic differentiation linked to

http://ncatlab.org/nlab/show/types+and+calculus#differential_lambda_calculus

http://www.sciencedirect.com/science/article/pii/S1571066112000473

http://ncatlab.org/nlab/show/dagger-compact+category I've seen automatic differentiation linked to

http://ncatlab.org/nlab/show/types+and+calculus#differential_lambda_calculus

http://www.sciencedirect.com/science/article/pii/S1571066112000473

Add a comment...