Can someone explain to me what a monad is?

Can someone explain to me what a monad is?

Other urls found in this thread:

sean.voisen.org/blog/2013/10/intro-monads-maybe/
twitter.com/NSFWRedditImage

burrito

Google it.

Another word for "testicle", I believe

A monad is a generic type constructor with the operations bind and return (sometimes also called unit).
Let a be any type. Then you get a monad by defining a type constructor M, such that:
return has the type a -> M a,
bind has the type M a -> (a -> M b) -> M b

The reason why monads are so difficult to understand at first is that they're an abstract pattern. The only way to understand it, is to find concrete examples that fit the pattern, because it's always easier to understand some concrete example rather than an abstract definition. Once you've seen enough examples you'll recognize the similarities and then you'll be able to identify the pattern. A few that are easy to understand are the maybe monad and the list monad.

It's the basement segment of the Tartarus in Persona 3.

Understanding is measured by how well you can explain something.
You're spouting gibberish and obviously have no idea what you're talking about.
NEXT!

The quality of an explanation is not measured by how well some particular person understands that explanation.

The inherent joke here is the old as in ancient meme that once you understand what a monad is, you lose the ability to explain it to others.

sean.voisen.org/blog/2013/10/intro-monads-maybe/

I know all the monad jokes, I just wanted to make that point.

Well, it is a good point

a monad is a context

>a context
So it's a state? That you mutate? Or that mutates whatever you pass in?

Forget fucking monads. The real question is what the fuck a zygohistomorphic prepromorphism is.

YES!
First one for "a monad is just a monoid in the category of endofunctors.."

Basically you wrap things in other things, so you can do operations with them. Then you unwrap them.

Think of ascii symbols that get wrapped to strings. Now you can append those strings (i.e. "bla" + "blu" = "blablu", or: "bla" + "" = "bla") and still have strings. And eventually you can turn a list into ascii chars again.

in pure languages your don't mutate, you create a modified copy
ofc with the exception of impure stuff needed to do io

>Basically you wrap things in other things, so you can do operations with them. Then you unwrap them.
It's already been said:

Meh.

But it was a different wording, that doesn't count.. ;__;

>A monad is just a monoid in the category of endofunctors.
Pretty much this. I don't get what everybody's problem is.

fn :: Int -> Int -> Maybe Int
fn x y = if x Int -> Maybe Int
fn2 x y = do
first_res

OP: What is a monad?

Sup Forums : It's a burrito. It's a generic type constructor. It's a context. It's a wrapper. It's a modifier. It's a copy-modifier. It's glue.

Either functional programming is super autistic, or I'm having a stroke because I can't fucking comprehend these contradicting analogies.

analogies don't have to be consistent, they are just a tool to express something in a easier to understand manner

fn :: Int -> Int -> Maybe Int
fn x y = if x Int -> Maybe Int
fn2 x y = fn x y >>= (\x -> fn (x * 2) y)

main :: IO ()
main = do
print $ fn2 5 10
print $ fn2 10 5


is what this desugars to
the >>= (and >>) functions are responsible for implementing the per-line glue logic of the given monad
the only difference between them is that >> ignores the result of the previous function

in the case of maybe the per-statement binding logic is
(>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b
(>>=) m g = case m of
Nothing -> Nothing
Just x -> g x

But they're confusing me and contradict each other. How is this supposed to help me understand?

the only way to learn monads is by dealing with them and reading lots of explanations

you can't actually understand monads, you have to mould your thinking around them, to think in their axioms instead of words and analogies

you put things into a box and you interact with said things only via the bind method. also some autistic laws need to apply like composibility (they should be easly chainable) associativity (like the one in maths or pure functions).

i think the reason why functional programmers use them is because they want their types to encode more informtation like a possible null value (Maybe monad) sideeffects (IO monad) a possible failure (Either monad) but I'm not a functional programmer. if I am wrong feel free to point my mistakes out, might learn something here as well.