What is a Monad and what is it for?

Asked

Viewed 995 times

14

I remember at the university it was explained to me what a monad, but time has passed and I no longer know what he is. This is also due to the little contact I have with functional languages.

In programming, what is a Monad? What is its use?

You can give an example of a use?

  • 1

    An answer to this will be quite extensive, it is an abstract concept very difficult to explain. This link has a very funny explanation: http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html

  • 1

    I found a good example here, if you want me to translate, but it’s in Haskell. http://stackoverflow.com/questions/44965/what-is-a-monad

  • 2

    @Marconi Thanks I’ve seen some answers there. It’s up to you to decide whether to do a translation or not. One best thing you can do is summarize the content of the various answers in a reply from you.

  • @Marconi a translation would go well...

  • 1

    The article Tacking the Awkward Squad Simon Peyton Jones is the best intro to monads I know. It explains well what a Monad is because they are so necessary for programming in Haskell. In other languages other than monads not being so necessary, it is difficult to abstract about convocê not so much about monadas and it is difficult to abstract about the concept of monadas without "kigher kinded polymorphism", which is an advanced type system functionality.

  • 2

    I translated the post I mentioned above. As I said, I think it would be difficult to explain what Monads are here (without writing a book), so I thought putting the answer elsewhere (Medium, in my view easier to create a post - even more a lot of images) and share it here makes sense in that context. 

Functors, Applicatives e Monads explicados com desenhos: https://medium.com/@julianoalves/functors-applicatives-e-monads-explicados-com-desenhos-2c45d5db7d25#. l56dxh4k4

Show 1 more comment

1 answer

2


A Monad, briefly, is simply a wrapper of some value.

Example:

function Maybe(value) {
  return {
    value: value
  }
}

const maybeString = Maybe('Novo Post No Blog')
maybeString.value // 'Novo Post No Blog'

const maybeNull = Maybe(null)
maybeNull.value // null
  • 2

    Mauritius, a tip. Select the code and click Ctrl + K leaves it formatted. Welcome to [en.so]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.