Live data from Hacker News

Monads are monoids in the category of endofunctors

sambernheim.com

191–200 of 241 posts

Re: Monads are monoids in the category of endofunctors

#191
post #74
post #49

Earlier quoted context omitted.

Communication is a two-way street. When someone is making an effort to learn, most FP advocates will happily make an effort to teach. But someone who comes in with guns blazing doesn't get to complain about being met with hostility, and if telling someone they're wrong when they're wrong is gatekeeping then it's a kind of gatekeeping that we need.

Being a teacher is a labor of love. There’s nothing wrong with a student coming in with any attitude. This attitude justifying gatekeeping reminds me of Stack Overflow - mods tired of seeing the same wrong questions asked. But it’s a Q&A site and the purpose is for people to get answers to their questions.

A Q&A website needs both people who ask questions, and people who answer them. Perhaps the latter even more than the former. You can ask a question on stackexchange and have it answered by Peter Shor. Not having the platform inundadated by dumb repetitive questions and homework problems is the compromise you need to retain such talented people on your platform.

If you want an example of what happens to a Q&A site without any gatekeeping, look at Quora.

Re: Monads are monoids in the category of endofunctors

#192
post #48

Earlier quoted context omitted.

Functors are type constructors, not functions (which map values). But you could be forgiven the misunderstanding, because it is easy to trip over this distinction given the identical syntax. So, to make this absolutely clear, a monad is a type constructor in functional programming. This is why I personally prefer the more “creative” explanations of monads, because they attempt to explain what the monad is doing to th…

>Functors are type constructors So why can't we just call the damn things 'Type constructors'?

A functor has three things: 1. A type constructor 2. A "map" function 3. A "flatten" function

So basically it is just a parametric type such as List which has a type constructor so you can get a concrete type (eg List), a map function which takes a function f: A => B and and turns it into a function List => List, and a "flatten" function with will turn a List> into a List.

The last part is what allows "flatMap" which takes a function f: A => List and turns it into a function List => List and is really just a shorthand for doing map and then flatten.

Re: Monads are monoids in the category of endofunctors

#193
post #137
post #64

Earlier quoted context omitted.

What makes a type constructor a functor, what's the difference

I might get flack from the FP purist crowd, but I like to think of functors as containers + context. - 5 is a value. Its type is int - int is a type - T is a type parameter. Like the x in "f(x)", we have to pass one in to evaluate it - List is a type constructor. It takes a type, T, and spits out a new, "compound" type. It will "contain" T's. - [3,5,7] is a list. Its type is List . We fed the type "int" to List to co…

I like your approach. However, I don't think that this:

- List is a functor because it "contains" T's. List "contains" ints.

Is really correct. I believe a `Container` becomes a functor only if it also 'has' (can have?) a function that can take a function and apply it to all values in the 'container'. So, a 'map' of some sort.

I mean, I see your explanation of 'map' later on. It's also probably true that in real world software engineering contexts any 'container type' of that kind would also be one that either has or can naturally have a `map'. It's just that if someone willing to understand this read your comment and went: "Aha! Some container thing is a functor because it contains things!" I think they'd gain incorrect understanding.

Not that I'm an FP guru, so..

Re: Monads are monoids in the category of endofunctors

#194

There’s a few gaps in this explanation that my deductive completionist brain is looking for. Namely, I’m wondering what kind of thing is even capable of being a monoid and an endofunctor at the same time. Mathematically, a monoid is a set (or collection to be more general) closed under a binary operator (the monoidal product) and with a distinguished identity element. An endofunctor is a mapping from a category to it…

The trick is that it is not a monoid AND and endofunctor but of monoid OF endofunctors. The whole "monads are monoids in the category of endofunctors" was a joke because it is a needlessly complex way of describing what a monad is.

Re: Monads are monoids in the category of endofunctors

#195
post #56

Earlier quoted context omitted.

> why a Functor is slightly more than just a Mappable Explain that again?

A Mappable would be anything that has a `map` function. A `Functor` is a something that has a `map` function _AND_ obeys the rule that calling `map` with the identity function produces the same result. ie: say I have some value `f` that is a functor. If I call `map identity f` I should always get back `f`. The mere existence of a `map` function doesn't imply this law holds. The identity function always returns it's a…

What is a good example (not contrived) of a mappable non-functor?

Re: Monads are monoids in the category of endofunctors

#196
post #74
post #49

Earlier quoted context omitted.

Communication is a two-way street. When someone is making an effort to learn, most FP advocates will happily make an effort to teach. But someone who comes in with guns blazing doesn't get to complain about being met with hostility, and if telling someone they're wrong when they're wrong is gatekeeping then it's a kind of gatekeeping that we need.

Being a teacher is a labor of love. There’s nothing wrong with a student coming in with any attitude. This attitude justifying gatekeeping reminds me of Stack Overflow - mods tired of seeing the same wrong questions asked. But it’s a Q&A site and the purpose is for people to get answers to their questions.

> There’s nothing wrong with a student coming in with any attitude.

A student can definitely have an attitude that prevents them from learning effectively though. If anyone wants to see the use of correct terminology as "gatekeeping" then they are of course free to do so but the obstacles to learning the subject that such a mindset creates are then a logical consequence of their actions and entirely their own fault.

Re: Monads are monoids in the category of endofunctors

#197
post #5

Wait, a functor is just a pure unary function? And an endofunctor is just one of those where the argument type and return type are the same? This could have been explained to me years ago, in five minutes? 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 -…

Welcome to higher math! You know, those PhDs and tenures need to be deserved, so why not obfuscating simple concepts to get ahead?

Re: Monads are monoids in the category of endofunctors

#198
post #113

Earlier quoted context omitted.

Many thanks!! So is it something like Class > thisistypeconstructor(Class strClass) And if I generify the types above, maybe something like thisistypeconstructor( )

Not quite - the type constructor is the thing that does the same thing with the types themselves, not with Class (which is sort-of-but-not-really a way to represent types as values). In Java or C# there's no way to actually represent a type constructor (e.g. you can't have a class that takes a type parameter F that could be List or Set, and then you use that type to form F within the class itself and it will be List…

For example in C++:

  template class F, class T>
  using apply = F;

  static_assert(is_same_v, list >);

Re: Monads are monoids in the category of endofunctors

#199
post #26
post #5

Wait, a functor is just a pure unary function? And an endofunctor is just one of those where the argument type and return type are the same? This could have been explained to me years ago, in five minutes? 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 -…

> 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 -…

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

From the ancient Greek "endo" meaning "within/inside" (as in "within the same group of things").

See also endogenous (endo + genesis, the latter the ancient Greek for born), meaning "born/created inside".

Post reply on HN