r/functionalprogramming • u/jhuni • Feb 15 '23
Category Theory The logic of functional programming
http://lisp-ai.blogspot.com/2023/02/the-logic-of-functional-programming.html
12
Upvotes
r/functionalprogramming • u/jhuni • Feb 15 '23
View all comments
1
u/kindaro Feb 15 '23 edited Feb 15 '23
Aside: Why is the function
assoccalledassoc? «As sock»? What does it have to do with socks? Or with associativity?So, I kind of understand where this is going, mostly thanks to our previous conversation with the author.
The example where we transpose, add and multiply matrices can be understood like so: Suppose you have a lazy matrix in Haskell. You do something with it, then pattern match to extract a single entry and print it. Where can the matrix be undefined so that your program still works? Which values does the computation need to force?
This shows that there is experimental content to this theory. We can make various assertions about how function «move information around» and test them with say
QuickCheck. (Indeed we can, I had written such strictness checks.)The lonely commutative diagram is lonely. It is not clear even what category the arrows belong to. Are the standing arrows lens? They are called locators, and we found that locators are lens. But then laying arrows are also lens… This does not make sense. Maybe the standing arrows are the «view» components of lens? Then, A is more or less C × … and B is more or less D × …. The diagram then says that function touches exactly the component C of the product A ≈ C × …. So, function is really C × X → D × X for some X.
For example, the function permute quadruple: X⁴ → X⁴ is described by four diagrams like this. We can check this experimentally by setting all components of a quadruple to
undefinedbut the first, applying permute quadruple and looking at the twoth component — it will be defined, the program will work.Overall, I think this is an interesting and even necessary line of inquiry.
It has long since bothered me that some functors(namely, products)are like containers while others(namely, exponents)are not. Exponents do not get lenses, and this is what makes them decisively unlike containers — they do not contain anything you could look at.¹ So, with containers, the immediate question to ask is:«What view of the input container do we need to have defined in order to compute this given view of the output container?»
It seems we need to get a bunch of views of the input container, a bunch of views of the output container, and get a relation between these views. I reckon the work of /u/jhuni, in a fairly cryptic way, attempts exactly that.
¹ P.S. This is wrong. What was I thinking? Functions f: X → Y gets lenses so far as X has decidable equality. The simplest lens is an element x: X. We go like so: view x f = f x and set x y f = λx'. if x ≡ x' then y else f x'.