Monads are contracts… the similar concept to the “interface” from java and go.
Monad is a concept from category theory, and it was (maybe not properly, that’s my suspicion) exported to the programming world. A monad in the programming world is just a interface saying that you must implement three methods (as declared on the “Monads laws”: constructor, return and bind.
/Untitled-376.png)
https://wiki.haskell.org/Monad_laws
ChatGPT:
The
**>>=**** **operator allows you to chain multiple Lwt computations together in a way that makes it clear how the results of one computation are passed to the next.
another example from ocaml:
For our purposes, a monad is a structure that satisfies two properties. First, it must match the following signature
This sounds exactly like “interface” concept right?
module type Monad = sig
type 'a t
val return : 'a -> 'a t
val bind : 'a t -> ('a -> 'b t) -> 'b t
endhttps://cs3110.github.io/textbook/chapters/ds/monads.html
This is everything that a monad is.
Well… But where is all the exoteric math that isolate and prevent side effects inside our “””PURE””” program? IT DOESN’T EXIST AT ALL.
Look my friend, **the side effect will happen soon or later ← *****This is a fact.***
The only thing that monad can do for us here, is** to delay that it occurs.**

The argument that monads bring is: The side-effects will be produced by the compiler and only executed at runtime, not by the pure language itself. In another words, the language remains pure (or looks like pure), but the execution is dirty as it should be.
So at the end, it’s all just a mental trick to keep your mind inside the “functional pure-way of thinking”, and do not make you worry about effects when coding your pure program”
As a matter of fact, even haskell source knows it, and that is why it will always demand that you separate you “pure functional code” from your “pseudo-pure functional code” (the parts that use monads to “””isolate”””” your effects).
random chat with @sapatenis about monads:
ainda n consegui começar a ler sobre algebric effects
mas monad me saturou man
é muito errado dizer q isso impede side effects
o side effect vai acontecer lol
o grande argumento é: "ah mas usando um monad, quem vai produzir o side effect é o compilador e o runtime"
🥴
se monad fosse realmente um isolamento/container de effects
haskell n ia exigir q vc separasse seu código puro do seu código pseudo-puro (q usa monads)
pq no fundo o monad não torna nada puro
ele só serve para criar uma gambiarra mental
pra vc n precisar pensar no effectChatGPT WRECKEDDDDD BIRRRRRRRR
/Untitled-378.png)
/Untitled-379.png)