Live data from Hacker News

Monads are monoids in the category of endofunctors

sambernheim.com

121–130 of 241 posts

Re: Monads are monoids in the category of endofunctors

#121
> This phrase is the cheeky line to (somewhat) formally define the monad

It's actually a satirical joke[1] that people started taking way too seriously. Honestly, imho people should never use this line when explaining monads. It's like saying 'C is a purely functional programming language!' because Conal Elliott, around the same time, wrote[2] a parodic blog post making fun of purely functional programming zealots.

[1] https://web.archive.org/web/20210824072932/https://james-iry...

[2] http://conal.net/blog/posts/the-c-language-is-purely-functio...

Re: Monads are monoids in the category of endofunctors

#122
post #104

Earlier quoted context omitted.

They said "It's like when the medieval Catholic Church refused to print a bible in anything but Latin so that they'd remain the sole authority on its content." and concluded with "shame on those who maintain this status quo." That's pretty "guns blazing" in my book.

> "It's like when the medieval Catholic Church refused to print a bible in anything but Latin so that they'd remain the sole authority on its content." The debate is about using language as a gatekeeping mechanism. The analogy is spot on... > "shame on those who maintain this status quo." A person shows up eager to learn, expresses gratitude, feels scorned at all of the language-based gatekeeping that goes into this…

> A person shows up eager to learn, expresses gratitude, feels scorned at all of the language-based gatekeeping that goes into this topic.

They expressed gratitude for those who told them easy falsehoods and scorn for those who told them harder truths, characterizing such honesty as "gatekeeping". That's not the action of someone eager to learn, it's someone who's eager to avoid learning, like those politicians who, rather than put in the effort to understand the economic implications of their policy, go shopping around economists until they find one who gives them the answer they want.

Re: Monads are monoids in the category of endofunctors

#123
post #100

Earlier quoted context omitted.

It's not an artificial barrier, you just didn't learn anything useful yet. So now you know what the words mean, but they mean super mundane stuff that you've probably dealt with a hundred times. You already knew how to use map and array concatenation before you even heard of the word monad. There's some magic to these words, but that magic is in how they're used to create new software, real things you can do with the…

I should be clear: you don't have to sell me on Haskell or these other concepts. I would love to add all that stuff to my toolbelt. I'm suggesting that the zoo of new terminology makes the effort barrier to doing so much higher than it needs to be. I'm sure some of it really is warranted, but my experience looking at formal math and logic is that they make things a lot harder than they need to be by introducing terms…

Alright, but you were praising the article for conveying the meaning of the words, when those meanings are useless without some sort of interesting application.

I believe people find monads difficult to grok not because the definition is hard to remember, but because the situation in which it is useful to distinguish the type class is abstract and frankly not super useful in most cases.

Funny thing about zoos of new terminology, back when I was an undergrad I found the type classes to be a confusing subject. Then one day I realized that type and class are basically synonyms so you might as well call them type types or class classes, which totally cemented the idea for some reason. My brain had been getting stuck on this random terminology and this just unclogged it.

Re: Monads are monoids in the category of endofunctors

#124
post #118
post #103

Earlier quoted context omitted.

> instead you're building a container (a monad) of instructions of what side effect having operations to do, and what should be done with the results. The Haskell runtime then takes this monad and unwraps it layer by layer, each layer executing the side effect having instruction and using the results of the side effects as input for unwrapping the next layer. Note that this is the implementation of a specific monad -…

> But the interesting part of Haskell's I/O isn't the implementation, it's the (pure) API that it uses, and Javascript has nothing like that. No, I insist JavaScript really has a pure approach to I/O, quite like Haskell. There is literally no side effects except for application state mutation from the perspective of a JavaScript function (if you disregard the few deprecated synchronous API's). And this pure API has p…

> There is literally no side effects except for application state mutation from the perspective of a JavaScript function (if you disregard the few deprecated synchronous API's).

That's a pretty big "except" - there are no side effects except for all the side effects (and there's nothing unique about JavaScript there, that much is the same as almost any other language). JavaScript's approach to I/O, like most languages, uses things that look like functions but aren't functions, in that they give different outputs for the same inputs. The whole point of Haskell's I/O system, the thing that separates it from other languages, is that it doesn't do that; in Haskell your functions are actually functions and I/O operations are very clearly not functions.

Re: Monads are monoids in the category of endofunctors

#125
post #122

Earlier quoted context omitted.

> "It's like when the medieval Catholic Church refused to print a bible in anything but Latin so that they'd remain the sole authority on its content." The debate is about using language as a gatekeeping mechanism. The analogy is spot on... > "shame on those who maintain this status quo." A person shows up eager to learn, expresses gratitude, feels scorned at all of the language-based gatekeeping that goes into this…

> A person shows up eager to learn, expresses gratitude, feels scorned at all of the language-based gatekeeping that goes into this topic. They expressed gratitude for those who told them easy falsehoods and scorn for those who told them harder truths, characterizing such honesty as "gatekeeping". That's not the action of someone eager to learn, it's someone who's eager to avoid learning, like those politicians who,…

> scorn for those who told them harder truths

Can you paste me in your post where you did this? (Note: you can't). I'll even paste your response, so you can remember better:

>> Wait, a functor is just a pure unary function?

> No.

>> And an endofunctor is just one of those where the argument type and return type are the same?

> Yes - "endo" means that in general. E.g. endomorphism.

>> Sometimes it makes me mad that so much confusion (and as another commenter put it, gatekeeping) has been sown in FP circles through the invention of pointlessly-obfuscated terminology for everything (and through - among many in those circles - a lack of interest in connecting the very simple dots that would allow masses of people to understand these concepts). It's like when the medieval Catholic Church refused to print a bible in anything but Latin so that they'd remain the sole authority on its content.

>> Kudos to the OP for cutting through some of that, but shame on those who maintain this status quo.

>> Edit: assuming it really is that simple. Some in the comments have suggested parts of the OP were wrong, so I'm curious to see discussion.

> The precise terminology is vital; it's how we avoid these errors when talking about this very abstract stuff. Given that the OP is very wrong, precisely because of the kind of attitude you've taken here, I hope you'll take this opportunity to reconsider your views.

Where in this block did you give them "harder truths"? I see "No", "Yes", and then saying "reconsider your views". Again, the purpose of your post clearly wasn't to help, provide value, enable, but instead to disparage. Or, you know, gatekeep.

Re: Monads are monoids in the category of endofunctors

#126

Hands up if you've never actually seen FP out in the wild doing something. Not saying it's not out there or useful - just saying that after 20 years I'm yet to come across it once.

Well... chances are you've made thousands of phone calls through switches running Erlang. You may have used Emacs, Discord, Facebook, Pinterest, Spotify, Font Awesome, xmonad or visited web sites running Elm or an Elixir backend... or even driven a Volvo.

Here's a list of companies using Haskell, with similar links to other functional languages: https://github.com/erkmos/haskell-companies. It includes names like Facebook, Tesla, Klarna, Target and Kaspersky.

Not to mention the FP paradigms used in Python, C++ and other languages. In fact, if you've never come across FP "in the wild doing something" then I suspect you're living very much off-grid.

Re: Monads are monoids in the category of endofunctors

#127
post #82

Earlier quoted context omitted.

You see, there's a bit of irony here in characterizing jargon as gatekeeping, because in the author's attempt to distill it, some pretty critical stuff got lost in translation. I share the sentiment that FP jargon can be impenetrable to the uninitiated, but the same can be said about programming jargon to non-techies: it may sound like gatekeeping to talk about "closures" but there's technical reasons why closures ar…

I absolutely think this is nitpicky, and a perfect demonstration of the pedantry I'm talking about: > Array.prototype.map is not monadic. The signature of the callback is `(T, number, Array ) => U`, which is most certainly not unary (and for that matter, using JS to illustrate FP is fundamentally problematic since JS isn't side-effect-free to begin with). The unspoken understanding in the OP is that we're only using…

It's not beside the point, though. It's a crucial aspect of FP!

Perhaps I'm getting a different reading from the article than you, but as someone who's gone in and out of this rabbit hole, I found that the author was making some pretty stretchy claims. For example, he says "It may also seem like every monad that is needed already exists. Some common ones are" and proceeds to name Arrays and Promises, neither of which can be used in functional composition beyond the very basic `foo.map(f)` (and may break even then, as per my trivial example above!)

It's fine to try to use a non-functional language to try to explain functional concepts to those who are familiar w/ JS but not FP, but also keep in mind that you may be misunderstanding unknown unknown nuances because of the misappropriation of one domain (JS) to explain another (FP). You yourself are an example of someone who seemed to be about to take a mischaracterized technicality at face value before an avalanche of people started pointing out issues. How do I know to what extent you or someone else understands the implications of functions not always being endofunctors, Arrays not actually being monadic, or why map vs fantasy-land/map matters?

There's a real cost when people come out of reading articles thinking they know more FP than they actually do. This exact discussion about strictness already had implications to the design of Javascript itself: the algebraic consistency argument was brought up while Promises were being specified, but it got dismissed and we ended up with non-monadic promises (and shitshows festered all over the place as a result, e.g. rxjs had to special case them, and we have stuff like fluture.js because why not have multiple future types). The Fantasy Land project itself was created out of spite of a dismissive comment in the promises discussion calling algebraic consistency "fantasy land". On another occasion, one of the React core team members went on twitter at one point saying react hooks are pure (and don't even get me started on algebraic effects). The amount of misunderstanding surrounding FP - even among JS engineers at FAANG - is frankly scary and "loose-is-fine" mentality seeping into the design of widely used APIs is not exactly ideal.

Re: Monads are monoids in the category of endofunctors

#128
post #88

Earlier quoted context omitted.

> `a -> b -> f a -> f b` (a -> b) -> F a -> F b; the parentheses are critical. I don't fully disagree with your point, but if you're going to emphasize rigor and definitions, it would be wise to make sure you're not setting people on the fence up for mistakes akin to those in the original post. (You also called it `F` and then used it as `f`.)

To add, I suspect that the Haskell type notation is not intuitive to people not familiar with it. For anyone wondering, (a -> b) -> f a -> f b means "A function taking a function from one type to another "(a -> b)" and a functor applied with one type "(f a)" and returns a functor applied with another type "(f b)".

I do think familiarity plays a big role. I find the Haskell syntax much more pleasant than Java, even though I'm perfectly familiar with both.

The equivalent signature in Java (if we could abstract over type functions) would be:

    interface Functor> {
       Function, F> map(Function f);
    }
You'll find very similar in Scala's `cats`, up to some currying and reordering. [0]

[0] https://typelevel.org/cats/typeclasses/functor.html

Re: Monads are monoids in the category of endofunctors

#129
post #41

Earlier quoted context omitted.

> a monad is a type constructor Now explain what a "type constructor" is, otherwise these words are worthless.

Here's how I like to think about things: Values are things . Concrete. Since we are manipulating computers, a value is really just some abstract symbols--1s and 0s occupying a slot in memory. The meaning of the symbols exists on a higher level, what we usually call semantics . Types are a well-studied method to attach semantics to blocks of otherwise meaningless (but concrete!) symbols. By declaring a variable (which…

> Note that I'm using the commonly recognized "generic type" angle bracket notation to deliberately avoid the confusion of Haskell's pedantically minimalist syntax.

I really appreciate this. I know the Haskell syntax kindasorta, but my brain just doesn't grok it well. Vs anything along the lines of Generic[Type] or Generic is just far more familiar for most audiences, myself included.

The people whom Haskell type syntax makes sense for are largely not the ones trying to learn this stuff.

Re: Monads are monoids in the category of endofunctors

#130

> This phrase is the cheeky line to (somewhat) formally define the monad It's actually a satirical joke[1] that people started taking way too seriously. Honestly, imho people should never use this line when explaining monads. It's like saying 'C is a purely functional programming language!' because Conal Elliott, around the same time, wrote[2] a parodic blog post making fun of purely functional programming zealots. […

Come onnn.

The phrase that forms the title of this post is very close to what (CT giant) Saunders Mac Lane wrote, quite seriously. In fact it's missing the word "just"! Iry was inspired by Mac Lane, but you seem to have got the wrong end of the stick on the actual status of these words.

See, for example, https://stackoverflow.com/a/3870310/14768587

Post reply on HN