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
Show parent comment
4
u/jhuni Feb 15 '23 edited Feb 15 '23
So I want to clarify that this blog post is more like a personal journey, than some distilled collection of concrete applications and results. I want people to be able to empathize with me and understand my own journey and where I am coming from. Its an introduction, like you suggested I write. That is why I explain personal tidbits like how I came from JavaScript programming and then learned Clojure, and things like that.
No but they were new to me in 2012, when I first got started with functional programming. When I first started I considered what we now call lenses to be "place forms" following the terminology in Common Lisp: https://lisp-ai.blogspot.com/2012/04/place-forms.html
At the same time, I was working a lot with reversible functional programs. Basically, by defining a reversible function as a pair of a function and its inverse. I talk about this emphasis on reversible functional programming here: https://lisp-ai.blogspot.com/2012/07/wipe-place-forms.html
So if you look back at the order in which things first appeared new to me it looks something like this (1) getting in to functional programming sometime as it started to get more mainstream (2) first encountering methods like assoc (not sure why its called that...) and then (3) learning about Common Lisp place forms and lenses (4) starting to work with bijections and considering things up to isomorphism.
All those things were important to the development of my thought which is why I include them in roughly the order in which they appeared to me. Even the section of the varied behavior of functions is something that I knew about a long time ago. The section on the transport of data is where I moved beyond my early development as a functional programmer to create a satisfying categorical understanding of the phenomena I was seeing before
This is a good point because it demonstrates how some kinds of information dependence can fit into a system of lazy evaluation.
They are not lens because that is too restrictive. There are many getter functions that describe places and locations within data structures that can not be made in to lens. The full theory of commutative squares in the topos Sets-> is more general, so we will go with that. Remember the names like locators are purely for educational purposes in this setting, because I don't want to have four functions with single letter variable names like f, g, h, k, etc.
I think you are getting it because that is exactly how I would have drawn it. Those four commutative diagrams describe the intuitive transport of data from the first place to the second, the second to the first, the third to the fourth, and the fourth to the third. All along they use the identity function to transport the data from place to place. Interestingly, functions can change data in transportation from place to place, so that they come out differently on the other side. That is what we call a transport function but if you prefer you can call them the f, g, h, and k functions as many textbooks do.
So remember what I said about how reversible programs, isomorphisms, and bijections became exceptionally important to me early on. Information is what is described by a function up to an isomorphism in its output. So its what is retained by a function without regard for its representation. You could think of it as a type of partition.
Its pure categorical logic really. Its an emergent property of Sets and its isomorphisms.
I am not a statistician, but the idea of two different types of approach to studying information has been explained by other writers. Here is an explanation from Tõnu Lausmaa:
Further information is available in the references. [1]
In the same way as anything else is moved under a commutative square diagram. You just have to think up to isomorphism. Take an epimorphism in Sets-> and consider the equivalence class of all epimorphisms in Sets-> defined up to output composition with an isomorphism.
So there is an adjunction between partition lattices associated to any function, which generalizes the adjunction between images and inverse images. What you are talking about is a partition inverse image, which lets you compute the partition of the input set you need to get the partition of the output set.
[1] Lausmaa, T. (2005). Extropy-based quantitative evaluation of finite functions. Proceedings of the Estonian Academy of Sciences. Physics. Mathematics, 54(2), 67. https://doi.org/10.3176/phys.math.2005.2.01