I don‘t get it

i don‘t get it.

Attached: 9AC5432F-7AC0-471C-9AC9-34DF7EAF9073.jpg (480x360, 11.35K)

>filtered
Just go back to OOP.

Attached: 1655070544671.jpg (1024x971, 78.46K)

you don't need to get it, Haskell is a toy language for math nerds that don't write software

you don't have to understand/know anything iToddler, just do your normalfag things like laughing at different color bubbles or browsing reddit

Monad is just a monoid the the category of endofunctors.

This.

Monad is the thing that lets you compose functions with multiple return values.

It has nothing to do with I/O operations except that some shills would wrap print function around monad and believe that its no longer procedural programming.

what's a monoid and what's an endofunctor?

so a monad can return multiple values at once?

a monad is a thingy with 2 other thingies.
one thingy composes/defines a bunch of functions and the other thingy takes the outputs of these functions and creates a type out of them all.

>Monad is the thing that lets you compose functions with multiple return values.

How's that different from a function that returns an array with multiple values?

So a monad is basically a glorified tuple?

Monads are basically functors m where nesting m(m(ma)) doesn't add complexity, ie. where multiple nesting can be flattened out in a unique way to a m(a).

The obvious example is mathematical expressions, eg. 3x+1. No matter how many times you nest, 3(2y+2)+1, 3(2(3+z)+2)+1, ..., you just get another expression that simplifies to a unique expression. Most example can be viewed as variations on this.

Another example is options. If you have an Option[Option[Option[int]]] then either you have a single int, eg. Some(Some(Some(3))), or it stops at None, so you can view it as just Option[int].

Same for lists, no matter how many times you nest them, [[1,2],[3],[4]], if you just read it left to right, you get a single list of numbers.

IO is a monad since if you have a program that produces a program (that produces a program that produces a program...) you can view it as just one program that executes the whole sequence at once.

Monads are something that barely anyone truly understands, it's clear from the terrible explanations everyone gives, whether they are ironic or not. If you can't explain i simply, you didn't understand it well enough.

A language built on such a vague concept is just a badly designed programming language, no amount of complexity worship is going to change this.

Attached: post-105197-0-29733400-1466430614.jpg (1200x999, 182.74K)

It's about structuring the code / function composition.

Consider this pseudocode (contrived, but that's not the point):

function ReadValueFromConfig(key, configFile):
var file = openFile(configFile)
var json = parseJson(file)
var value = json.get(key)
return value

It has no error checking. Let's assume that each function can return either a result or null:

function ReadValueFromConfig(key, configFile):
var file = openFile(configFile)
if file == null:
return null

var json = parseJson(file)
if json == null:
return null

var value = json.get(key)
if value == null
return null

return value

But now the code is littered with boilerplate.

This is the problem solved by monad (horrible name btw).
Insted of explicitly writing all those checks, you define a composition rule that says (this is not even pseudocode):

Monad "Optional": bind funcA and funcB =>
if funcA returns null, return null
otherwise, pass the result to funcB
finally, return whatever funcB returns

Then, you can use the first version of the code, but with an annotation saying that it's transformed using your monad "Optional":

function ReadValueFromConfig(key, configFile) using Optional:
var file = openFile(configFile)
var json = parseJson(file)
var value = json.get(key)
return value

In haskell the specific syntax sugar for that is called "do notation".

I fucked up the formatting, oh well

It's an interface with two functions

interface M {
flatten(x: M): M
return(x: A): M
}

(code)text(/code) with square brackets =
text

text
You get the point

Ffs

text

Text

It's just a functor in the terminal bicategory.

if you can flatmap it, it's a monad

What's a terminal bicategory

Attached: 1655118186680.jpg (300x360, 34.79K)

It's just a category of preassociative isomorphic groupoids.