News for hackers. Stuff that matters.
Re:Functors and Monads for People Who Have Read Too Many “Tu... by siraben on Saturday June 26, 2021 @12:11AM (#27639039)
As someone who studies both CS and pure math, it's quite interesting when I see posts that take a very operational reading of functors and monads, instead of its shorter and more precise categorical definition (as a mapping from one category to another that acts homomorphically over morphisms). That's not necessarily wrong, but it's an important thing to keep in mind when learning category theory through a programming context (e.g. Category Theory for Programmers by Milewski). When I tried to learn category theory in this way, past a certain point the abstractions felt too unnatural and arbitrary (e.g. lack of examples for adjunctions and free objects), whereas a good mathematical treatment of category theory would provide plenty of examples across different areas of mathematics such as algebra, topology and logic.

I strongly agree with valenterry's comment[1] here, that post gives is an approximate definition of functors, even omitting the functor law. In particular, it is explaining what an endofunctor is (in the context of FP, you mostly deal with one category anyway). Furthermore, even in Haskell, there is no such thing as the category of Haskell types[0] (because of things like divergence and partiality).

For the curious, I've recommended Program Design By Calculation[2] to a number of people to show how category theory can be used as a powerful tool to reason about programs in an FP context while not compromising on the mathematics (the target audience is undergrad CS majors).

EDIT: In particular, I have a bit of issue with this sentence after stating the signature of fmap, since it does not reference lawfulness.

> This is the full definition. There is no additional hidden machinery that Haskell is somehow automatically invoking when you "use a Functor".

[0] http://math.andrej.com/2016/08/06/hask-is-not-a-category/

[1] https://news.ycombinator.com/item?id=27638565

[2] https://www4.di.uminho.pt/~jno/ps/pdbc.pdf

Re:Functors and Monads for People Who Have Read Too Many “Tu... by bcrosby95 on Saturday June 26, 2021 @02:20AM (#27639611)
Because most people suck at taking abstract mathematical concepts and seeing how they could apply to code. Including me. Let's take the definition of a function:

> A function is a relation for which each value from the set the first components of the ordered pairs is associated with exactly one value from the set of second components of the ordered pair.

Cool, I have no idea what the fuck this means and how it is useful to me.

Oh wait, I use them every day.

Re:Functors and Monads for People Who Have Read Too Many “Tu... by hiker on Saturday June 26, 2021 @04:37AM (#27640221)
> Cool, I have no idea what the fuck this means and how it is useful to me.

> Oh wait, I use them every day.

Do you really? Do the `functions` you use even fit the above definition?

I bet you can think of infinite number of functions (bool -> bool). The above definition admits only 4 such functions.

Re:Functors and Monads for People Who Have Read Too Many “Tu... by bb010g on Saturday June 26, 2021 @05:33PM (#27646093)
There are only 4 (2**2) such pure functions. For type (Bool -> IO Bool), there are infinite (∞**2) such pure functions.
Re:Functors and Monads for People Who Have Read Too Many “Tu... by siraben on Saturday June 26, 2021 @02:32AM (#27639652)
That is the first definition stated in first-order logic, sure. But the operational reading of a (computable) function being something that takes in input and produces an output (via some algorithm) is still correct. It is possible to be both clear and correct with operational analogies. However, monads and functors don't readily admit an easy operational reading like functions.
Re:Functors and Monads for People Who Have Read Too Many “Tu... by ebingdom on Saturday June 26, 2021 @01:26AM (#27639346)
> Furthermore, even in Haskell, there is no such thing as the category of Haskell types[0] (because of things like divergence and partiality).

Divergence and partiality can easily be modeled by the category of complete partial orders and Scott-continuous maps. This is what you learn in, e.g., a course on domain theory and/or denotational semantics.

Andrej Bauer is mainly arguing that Hask isn't a category because no one has formally specified it. For example, we would need to come up with a policy on when two arrows are considered equal, and it's not clear what that notion of equality should be.

Re:Functors and Monads for People Who Have Read Too Many “Tu... by siraben on Saturday June 26, 2021 @01:38AM (#27639405)
Right, domain theory and denotational semantics let you talk about ⊥ in an order-theoretic setting, and I think it's also rich in connections between topology and lambda calculus. Though it might be the case that if functors already pose a pedagogical conundrum for programmers, Scott-continuity might be even harder to get across.

A quote from Bauer's post is particularly relevant:

> [I am arguing against] the fact that some people find it acceptable to defend broken mathematics on the grounds that it is useful. Non-broken mathematics is also useful, as well as correct. Good engineers do not rationalize broken math by saying “life is tough”.

Re:Functors and Monads for People Who Have Read Too Many “Tu... by catgary on Saturday June 26, 2021 @03:34AM (#27639935)
Brauer has clearly had a different experience with classical mechanics and engineering physics courses than I did…
Re:Functors and Monads for People Who Have Read Too Many “Tu... by drdeca on Saturday June 26, 2021 @01:24AM (#27639340)
Do you happen to know of any programming language which has explicit support for multiple categories?
Re:Functors and Monads for People Who Have Read Too Many “Tu... by hiker on Saturday June 26, 2021 @04:30AM (#27640182)
Lean[0]'s mathlib has quite nice formalisation of category theory[1] with plenty examples of concrete categories even sheaves and toposes.

[0] https://leanprover.github.io/programming_in_lean/#01_Introdu...

[1] https://github.com/leanprover-community/mathlib/blob/master/...