3 ms·
If you are not trying to use Haskell (which has monads as a workaround for certain problems) then what is the point having monads? The average developer doesn't
by pekk 10y ago
If you are not trying to use Haskell (which has monads as a workaround for certain problems) then what is the point having monads? The average developer doesn't care because they are working in an environment where monads aren't needed.
Trying to drag monads into arbitrary languages like Javascript isn't some kind of best practice, it's cargo culting.
- deleted 10y ago[deleted]
- andrewflnr 10y agoA Monad is a general-purpose mathematical structure, not just a workaround. GP gave you an example of something they're useful for, which you completely ignored.
- berdario 10y agoWhat's the point of having monads? You might as well ask what's the point of having Iterable<> when you're programming in C :) It's not that you strictly _need_ monads or Iterable interfaces, it's that they represent an abstract concept which allows you to solve problems in a generic and type-safe way I wouldn't probably "drag monads" into Javascript, but I'd surely appreciate Functors when programming in Javascript :)
- adrusi 10y agoHaskell doesn't have monads as a work-around. They are a useful abstraction because they capture a common semantic pattern found in many programming concepts. Nullable types, error handling, sequential execution, and asynchronous event handling are all concepts that can be described monadically. By describing them as monads and making the monadic pattern a core idea of the language, you can write algorithms that operate on any monad, so that you can write one function and have it be useful for both managing the execution of IO and error handling in a generic way. People have an aversion to monads because a the concept of a monad has no grounds in reality, kind of like complex numbers. It is an abstraction that is useful not because it describes anything, but because it is simply a useful way to think.
- vog 10y ago> If you are not trying to use Haskell (...) then what is the point having monads? I'm not sure how to answer this question, as my previous comment actually is the answer to your question. Promises are a great example. They are a mechanism that provides better encapsulation and is still easier to compose than using pure callbacks. (IIRC, Haskell made a similar transition: Monads haven't been in Haskell forever, many other ways have been tried before, but in the end turned out to be quite cumbersome and ugly in larger code bases. The introduction of monads was generally perceived as relieve in Haskell, and are becoming more and more popular in other non-lazy functional languages as well, such as OCaml.)
- coldtea 10y agoI don't think you understand monads. For one, only the IO monad could be said that is used in Haskell as a "workaround". Second, monads are fundamental mathematical objects, not some random kludge invented to solve some language's problems. Third, if you don't have monads in your language you still use them all the time, just implementing them yourself, in an ad-hoc and less flexible way.
- fpoling 10y agoCheck the Elm language. It built on top of monad ideas (but the language author avoids using the term for good reasons). It make programming web pages very compostable, scalable and maintainable. It shows that monads are really good fit with event-driven programming.
- WorldMaker 10y agoMonad is a mathematical term for certain forms of (categorical) abstraction. Yes, Haskell actively uses the term "monad" in the language itself to discuss these things, but that doesn't make them a "Haskell thing" any more than Fortran has mathematical formulas and thus all math is a "Fortran thing". Monads are also not a "workaround for certain problems", contrary to what you hear sometimes, but an attempt to generalize a number of seemingly unrelated concepts into a uniform interface. Uniform interfaces are good for programmers. This is the magic that monads bring to other languages as we get a handle of what the monad is for and what it does. You don't have to know what a monad is to make use of it. You don't need to know that Promises are a "continuation monad" to take advantage of the fact that async/await are simple tools to transform the "continuation monad" into something resembling synchronous code, which is a big win. (Meanwhile Haskell points out that you can go simpler than async/await for your monad bindings if you like and use the same constructs for other monads too, but language developers are taking this one step at a time and trying to hit a happy medium where they have the power that monad binding gives but the discoverability and debuggability of more bespoke solutions to individual monads...) Needless to say, it's not cargo culting so much as learning more about the very mathematical fundamentals of programming and using those fundamentals to build better languages with better features for better programs.
- tome 10y ago> monads as a workaround for certain problems No. Rather "monads capture the essence of certain problems".