Hacker News new | ask | show | jobs
by cess11 547 days ago
Monads aren't weird. Basically it's data structures you can map over and flatten, like a list or a maybe/result/option. Everyone who isn't extremely junior knows about them. There's some theory that ties into formal systems and blah blah blah, but you sure don't need to be janking your monoid in public to understand and use monads.

As for tooling, few people actually want immersive, robust tooling. If that was popular things like Pharo and Allegro wouldn't be niche. Most want crude text editing with pretty colours and not much more.

2 comments

> Monads aren't weird. Basically it's …

Says everyone after having spent months getting the hang of it and more months writing blogs about how everyone is wrong to think it’s difficult because when you think about it “ A Monad is just a Monoid in the Category of Endofunctors”

It’s incredible just how blind most programmers are to the time they spend on learning things to come to the point where they think a subject is simple and how they all assume that any junior should just listen to their magical recital of a boiled down explanation and immediately understand it at a fundamental level.

If they were called "flatmappable" (which is essentially what they are), people wouldn't complain so much about monads. But in Haskell you have to bend over backwards just to set a variable you think should be in scope, or to log something to the console, and monads are involved in achieving that kind of things.

Haskell is hard - monads in themselves not really.

Yes, if only people called it something different. Quantum mechanics similarly immediately understandable if you just call it mechanics of discrete amounts. No need to read a lot of books, do a lot of math or calculation. You now know quantum mechanics at a fundamental level because I have told you the magical recital of a boiled down version. I’ll get back to you with a link to my blog explaining why university courses on the subject should just be replace with a picture of a cat and my magical phrase which will have the same effect.

Honestly do you not even see how naive this idea is that the only thing standing between a subject that literally everyone spends a ton of time on getting good understanding of is a renaming or a catch phrase? Even people who read tons of blogs of “actually it simple just…” end up spending time getting to know it. And every one of those people writing those blogs spent a ton of time on it which is why they are writing blogs about their “eureka moment” that will forever make the subject and instantly learned matter.

I think you misunderstood my point...

There are so many things in programming that are hard to grasp at a deep level, but don't look scary to beginners (who misuse them without realizing). Monads look scary so they take all the blame. I'm not really proposing this, but I guess if monads were called something like "flatmappable", the focus would perhaps shift to the more difficult parts of Haskell: at the root, immutability and purity, and on top of that, the deluge of abstractions and ways to compose them. It wouldn't make Haskell any easier... it would just save the poor monad all the bad rap.

The weird thing is the word monad and the technical formalism. Practically speaking, I really don't see why I decent junior can't understand

  x = [1, 2, 3].flatMap(el => if (el % 2 == 0) [] else [ el ]) // x = [1, 3]
vs

  x = []
  for (i = 1, i <= 3, i++) { if (i % 2) == 0) x.push(i) } // x = [1, 3]
or some such. There are advantages and disadvantages to either style of programming. I actually don't like pure functional or imperative style because of the respective tradeoffs each make (functional style requires either significant runtime overhead or heavyweight compiler optimizations and imperative gets messy very quickly and is typically difficult to reason about as program size expands).
The problem is, that's not "monad"; that's the implementation of the monad interface specifically on an array. That's like claiming to understand "iterators" because you understand how to write an iterator implementation on an array, but then trying to take that understanding to an iterator that yields the primes in order. If you think "iterator == presenting each element of an array in order", and nothing else, you don't actually understand iterators, because presenting each element of an array in order is an iterator, not the concept of iterators. "flatMap" is a monad, it is not the concept of monad.
I think any language that has a flatmap type construct would also have filter functions that would be a lot clearer to read and write...

    (remove-if #'evenp '(1 2 3))
vs

    (mapcan
      (lambda (n) (if (evenp n) '() (list n)))
      '(1 2 3))
in Common Lisp for example.

(Yes I know the original is just a contrived example that you shouldn't read too much into, but...)

I don't understand shit about the formalisms and I don't care. If you look at my posting history you'll notice that I'm a very uneducated, very crude programmer.

This kind of data structure is like the next step after learning how the scalars work.

'Weirdness' is, as this conversation confirms, in the eye if the beholder. I _find_ ruby weird and non-intuitive.
It's a claim that monads are somehow supernatural, twists of reality, which is obviously not the case since a lot of people who have never learnt the word monad are using them daily in the form of Optional style types and lists and so on.