You have 10 seconds to explain why a Monad isn't just an over-complicated way of defining a Class and why Functional...

you have 10 seconds to explain why a Monad isn't just an over-complicated way of defining a Class and why Functional Programming isn't Object Oriented Programming with different terms to make functional programmers feel superior

Other urls found in this thread:

math.mit.edu/~dspivak/CT4S.pdf
twitter.com/SFWRedditGifs

>an over-complicated way of defining a Class
A monad is a type that implements the monad interface.
The interface consists of the two functions, η and μ in your image.

Watch the computerphile video. A monad is a way of generalizing functors. Or something.

Is it possible to explain what a monad is without greek letters or words like "endofunctors"?

how I can use this thing?

That video sucks especially if you dont know haskell

Monad is actually a specialization of Functor

Monoide is abstraction action/thing or anything.
Something had a set states and follow some rules.

Monad is one monoid follow some rules to bind, allow composition functions.

Maybe monad had contains some value or none, use to handler trouble null exceptions.

Exception monads are some state plus exception state.
I/O monads are some compute operation and state of I/O.
Monad could build collections or travel collections.

One variable could Store data
One function take data and return data
One high order function work take functions and data.
Monad could take data,compute expressions, compute process and return this process.
Functions takes monads could build computational process chain another functions.

Some more math definition
math.mit.edu/~dspivak/CT4S.pdf
Page 69 monoids

Categorie theory is high abstraction could contains OOP

Thanks, Pajeet.

the computerphile video is a guy trying to describe a class without saying "class" for 20 minutes

so from what I've gathered, a monad is certainly something, but no one is entirely sure what something is

it's a total goddamn waste of time

It's like a burrito

I always thought a monad was one of my testicles

As I see it it allows change of state because it can handle exceptions.
Anyhow I still think pure FP is a meme.

You are a simple retard.

>math.mit.edu/~dspivak/CT4S.pdf

So if I'm understanding this right, a monoid is a function that can be applied to pairs of possible states to produce other possible states with the additional restrictions:

That there's some possible state that when paired with any other state will produce the other state it's paired with (a no-op).

That the same combination of states should produce the same end result state regardless of the order in which the function is applied to them ( f(f(x, y), z) = f(x,f(y,z) )

What I'm still trying to understand is... why?

Yes.

By stating it's laws

On 235 same book, monad definition and some examples

What's I? The identity functor?

message passing vs referential transparency

monad is what satisfies the monad laws

>What I'm still trying to understand is... why?
A monad encapsulates state over a series of operations.

One the one hand, that is useful if you want to have a purely functional language that can handle e.g. I/O, where there is external and internal state involved. I guess even in Haskell it is not functional all the way down to the bare bones, but the monad abstraction at least exposes something purely functional to the programmer:
A function that does a computation *and also some I/O like writing to the console* is clearly distinguishable from a function that only does computation. The function that does I/O does get the I/O state as additional input through the I/O monad and returns the continued/modified state through this monad.
Thus, the function has no "side effects", because they are visible in the signature, becoming "main effects."

On the other hand, where monads are great and useful even if you’re not interested in functional programming wankery, is e.g. when you chain a number of operations where each of them can fail. In straight-forward imperative programming, you must check for error after each operation, and stop going on if there is one.
With a monad, you can just chain the operations without the error-handling-clutter after each step, because now your monad just goes into an "error state" after the first error occurs, and ignores the remaining operations.
Now your code has only one place where errors are checked, in the final line after all the steps.

>encapsulates state
so what state is encapsulated by the identity monad?

>In straight-forward imperative programming, you must check for error after each operation, and stop going on if there is one.

how is an error state different from an exception? You will need to handle the result anyway

Monads are good if you want to express special function composition behaviour without performing it explicitly. Having all existing logic apply properly to functorial types is a blessing.

ah, so a monoid is The Algebra. It all makes sense now.

monads are just continuations in disguise

in functional programming every function typically returns something. a function program is usually just a series of function called like a(b(c(d))) for short.
these function have type declarations. when you get deep enough into a program you realize you need to error check or have a function *sometimes* return a different value. but the functions are type checked so how do you do that?
by having a structure which acts at two (or more) types simultaneously and seamlessly.

You have 2 seconds to explain why these Gonads are not firmly planted down your throat yet, gayboi

A monoid is just a semigroup (an associative magma) with a neutral element.

>tfw only 122 IQ

µ looks like the operation but it should be second element of the triple, not the last.
And what set is I supposed to be?

>With a monad, you can just chain the operations without the error-handling-clutter after each step, because now your monad just goes into an "error state" after the first error occurs, and ignores the remaining operations.
>Now your code has only one place where errors are checked, in the final line after all the steps.

You just described a fancy way of throwing exceptions.

Please don't mix meme concepts like monads with functional programming.
And functional programming has nothing to do with OOP. Data and functions are clearly separated, not so in OOP. Mutable state is minimazed rather than incapsulated. You have no idea what you're talking about.

>all these bad explanations

A monad is a mathematical abstraction, a monad instance could be anything: IO monad, state monad, Maybe monad and even lists in Haskell, are just examples of something much more general.

For programmers, the most useful way to describe a monad is to think of transforming an object x of type X into a new object m(x) of type m(X) (e.g. the integer number 3 into the list [3]) and a way of transforming functions f : A -> B into functions m(f) : m(A) -> m(B) together with an operation >>= : (m(A), A -> m(B)) -> m(B) that satisfies:
m(f(x)) = m(f) (m(x))
m(id) = id
m (f . g) = m(f) . m(g)
which makes m a functor and
m(x) >>= f = f x
x >>= m = x
(x >>= f) >>= g = x >>= (\x -> (f(x) >>= g))

For the list monad, the function f will be transformed into f([x,y,...]) = [f(x),f(y),...]. And the operation >>= is just
[x,y,...] >>= f = concat [f(x),f(y),...]

uh, errm, eh uh...
Oh I failed. Looks like it wasn't a viable undertaking to begin with.

Also, if you still don't get it, don't worry, just practice and keep trying to use them.
But these analogies are useless and at the long run, harmful.

For those who know some abstract algebra, look into how freely generated algebraic structures gives you a monad for free.
Lists with elements of type A, for example, is just a freely generated monoid with elements of A.

This is a terrible explanation. Literally burrito-tier.

...

It's a specific kind of class, namely one that implements two functions (map and apply). Yes, it's literally just a formal way to describe this. Yes, haskelltards and computerhater think they're so 1337 for avoiding speaking clearly and directly. There are jokes like "a monad is just a monoid of the class of endofunctors, what's hard to grasp" or whatever but at the same time virtually NO blog/video/tutorial ever speaks plainly about them.

t. codemonkey

Hmm, but what if an object returned a changed copy of itself from every "mutating" operation!

>one that implements two functions (map and apply).
You are wrong.

Oops, typo,
Not* wrong

>how I can

Poo detected.

>There are people wasting their lives coding against some dumb mathematical abstraction they don't even understand, just to feel superior
Pretty sad, and no one ever managed to give a good and concrete reason to use monads in programming