{"id":20772858,"url":"https://github.com/rcardin/cat-notebook","last_synced_at":"2026-03-17T01:31:44.838Z","repository":{"id":82060521,"uuid":"197450246","full_name":"rcardin/cat-notebook","owner":"rcardin","description":"Notes on Category Theory, taken while trying to understand the Functional Programming","archived":false,"fork":false,"pushed_at":"2019-08-06T12:17:33.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-18T07:30:04.578Z","etag":null,"topics":["category-theory","functional-programming","learning","writing"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rcardin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-17T19:29:49.000Z","updated_at":"2019-08-06T12:17:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"9812ad23-7805-49d3-9a53-d4ea2b6fea64","html_url":"https://github.com/rcardin/cat-notebook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fcat-notebook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fcat-notebook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fcat-notebook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fcat-notebook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rcardin","download_url":"https://codeload.github.com/rcardin/cat-notebook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243112187,"owners_count":20238180,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["category-theory","functional-programming","learning","writing"],"created_at":"2024-11-17T12:23:16.552Z","updated_at":"2025-12-26T02:03:17.638Z","avatar_url":"https://github.com/rcardin.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Category Theory Notebook\n\nThe following is a not-exhaustive list of notes that I took while I was reading multiple articles and posts and books on Category Theory. At the end of this notebook, you will find the references, from which I took the notes.\n\nHappy reading!\n\n## Why should I learn Category Theory as a programmer / developer\n\nThe basic idea behind category theory is composition. The composition is the concept behind every programming paradigm. We compose procedures, objects or functions. We need to compose because we need to decompose difficult structures to manage complexity.\n\nIn functional programming, we compose functions, but also \"concurrency\", which means we can treat the concurrency execution of programs as an object that can be composed. This is a _killer feature_, because of the multicore hardware revolution.\n\n## Introduction: Arrows and Objects\nA category is a set of objects and arrows that go between them. Arrows compose: If there is an arrow between objects `A` and `B`, then there must be an arrow between objects `A` and `C`. This last arrow is called the _composition_ of the previous two. \n\nArrows are also called _morphisms_. Morphisms can be thought of as functions. Their composition is denoted by a small circle between functions: `g∘f`. Functions compose right to left. You should read the formula `g∘f` as \"_apply g after f_\", precisely in the same way you read the function `g(f(a))`.\n\nDifferent programming languages support function composition, using a dedicated syntax.\n\nHaskell provides the following syntax. Given the functions `f :: A -\u003e B` and `g :: B -\u003e C`, their composition is achieved through the function `g . f` (or `g ∘ f`, for the _hardcore_ developers).\n\nIn Scala, the composition has two dedicated methods, despite of you want to compose f with g or viceversa. Using the `compose` function, you can achieve the same semantics of the mathematical composition `g∘f`. \n```scala\nval fComposeG = g _ compose f _\n``` \nis equal to `g(f(x)`. Whereas, `andThen` has the opposite semantics. \n```scala\nval gAndThenF = g _ andThen f _\n``` \nis equal to `f(g(x)`.\n\n### Arrows composition properties\n\nThe composition of \"arrows\", or _morphisms_, must satisfy some propeties. In details, the composition must be associative and it must have a _unit of composition_.\n\nBeing associative means that no matter what is the order you compose three composable morphisms, they must always return the same result. In other words, it means the following.\n\n```\n(g ∘ f) ∘ h = g ∘ (f ∘ h) = g ∘ f ∘ h\n```\n\nThe unit of composition is an arrow that simply starts and ends in the same category object. In the case of functions, the identity function just returns its argument. In Haskell is defined as the following.\n\n```haskell\nid :: a -\u003e a\nid x = x\n```\n\nSuch morphim, when composed with any other morphism, returns the latter. Calling `id_a` the identity arrow for the object A, and `f:: A -\u003e B`, then we have that\n\n```\nf ∘ id_a = f\n```\n\nand that \n\n```\nid_b ∘ f = f\n```\n\n## Types and Functions\nComposition is at the core of Cathegory Theory. However, not any two arrows can be composed. The target object of the first arrow must be the same of the source object of the second arrow. \n\nWhat are types? A first attempt to give an answer to this question is that _types_ are sets of values. Sets can be _finite_, such as `Boolean`, or they can be _infinite_, such as `String`. Declaring `x` to be of type `Integer` means that the variable is an element of the integers' set. \n\n**Sets** is a particular type of category, in which objects are sets and arrows are functions defined between sets. Referring to a programming language, can we say that the types and functions defined in the language define a category? The answer is _no_. Unfortunately, the devil is in the details. A pure mathematical function does not compute any results for a function. It just knows that the function returns that result. A function defined in a programming language has to calculate which is the output of a function, given its input.\n\n## References\n- [Category Theory for Programmers](https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/)\n- [Learn You a Haskell for Great Good](http://learnyouahaskell.com/)\n- [Pattern Matching and Functional Composition](https://twitter.github.io/scala_school/pattern-matching-and-functional-composition.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcardin%2Fcat-notebook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frcardin%2Fcat-notebook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcardin%2Fcat-notebook/lists"}