What is a Monad? - The Last Monad Intro You'll Ever Need

preview_player
Показать описание

0:00 intro
0:47 Revisit array map
1:20 flatMap
2:52 Represent effects with types
5:24 What is a monad?
6:44 How does Promises relate to Monads?
7:40 Monads vs. Functors
7:59 do notation
9:08 Promise example
9:21 Array example
10:39 Maybe example
11:42 Writer example
14:39 Recap
15:23 Additional reading

B-roll:envato elements
Рекомендации по теме
Комментарии
Автор

A monad is simply a monoid in the cateogry of endofunctors. Didn't you know that?

sorvex
Автор

the steps to a monad are: functor -> applicative functor -> monad
easy to follow but useful samples helping in understanding the funtioning of a monad!

hansschenker
Автор

So I an program in a number of languages including haskell and I don't understand what that lower representation is. I mean I can look at it and kinda understand what it's says but it's basically explaining a concept by way of another concept I don't know what it is. Is that typescript or some c++ derivative. Why explaining something by using another foreign concept it just causes extra mental overhead and exactly what all those other failed teachers do.

newsofthenerd
Автор

Monads aren't just "a useless wrapper to do a side effect in purely functional programming land".

The best way I can describe monads is how I described it to another youtuber on their "purest coding style" vid - monads are tuples of the following 3 elements:
1. The context that changes with each bind
2. Injective functor that uses the value from the initial context and returns a new value
3. Surjective functor aka the bind that takes the new value and creates a new context that will hold this new value

FWIW the IO monad derives from the State monad. An IO monad can be defined as:
1. File handle/other IO related sockets to change via the runtime along with extra values to use with the handle/socket
2. Functor that supplies the line from the CLI
3. Functor (most likely implicitly defined in the prelude) that takes the string from readLn and creates the context to say "if we were the runtime, we would've read X characters from the file, so we're at this point in the handle"

SimGunther
Автор

我不喜歡用 side effect 概括 monad 的概念
我覺得這對一些 monad 來說有些牽強
例如 A -> Array<B> 作為 monad function 通常被解釋成有多種可能結果的運算過程
「有多種可能結果」是什麼樣的 side effect?

我想 side effect 這個詞或許來自 IO monad
A -> IO<B> 被當作帶有印出/讀取的運算過程
其中「印出/讀取」作為 side effect 來說很合理
因為它單純就是在運算過程中「順便」印出文字或讀取檔案
但這個「順便」對於數學家來說非常刺眼, 因此它被形容為不純函數
不純的部份因此被稱作 side effect

但對於 A -> Maybe<B> 和 A -> Array<B> 這種會改變流程控制的 monad 來說
用 side effect 描述就很奇怪, 它根本就不是「順便」造成的結果
A -> Maybe<B> 被解釋成「可能會失敗」的運算過程人們能接受是因為 C++ 萬惡的 throw/try/catch
把 A -> Array<B> 解釋成「有多種可能結果」的運算過程就完全是牽強的解釋
更不用提 continuation...

說到底 monad 關注的還是在他的數學結構
簡單來說就是 a monoid in the category of endofunctors
硬要給它一個程式上的直觀圖像本身就不合適

have-bear
Автор

I don't understand the purpose of the flatmap section at all. Flatmap is not somehow more related or better for monads than map. It's just two functions combined - map and flatten. You could do everything flatmap can do with those two, and it would be just as monadic a pattern.

Mikhanius
Автор

Hey, do you have an English version of your Currying video you referenced?

yashdelhiwala
Автор

Nice video, bro. I know fp dart package supports uses do notation but I couldn't understand what language you using in your examples. How do you make your animation for video, btw?

Nikage
Автор

My recommended section always has a monad video. I still don't understand what they do. And also, why are monads important?

hooman
Автор

The only problem I have with the usage of bind is that one doesn't call a function, but it does look like it. const = bind add2(init) is a bit weird. Functionally speaking bind would return a function that takes in something and returns that thing plus 2. I don't really like the syntaxis of assigning values to something whilst that value is an expression of the function its end value, instead a new function that just defines that x is add2(init). Bind does what exactly? It just unwraps it, applies the operation, and rewraps the result. The await keyword shows that it is waiting on an operation. Bind here doesn't serve its context here. To what are we binding? With what? A nice video non the less, but there are some holes in there that I can't seem to place.

LordErnie
Автор

Great video! I wish I could understand Chinese to watch all the other videos! All the best brother 💪

Filaxsan
Автор

下一個單元應該要到 applicative 了

從 Array<Option<int>> to Option<Array<int>>
或 Array<Either<Int>> to Either<Array<Int>>

莫秉禾
Автор

π[T] -> (T->π[U]) -> π[U]
Where ("T", "U") are generics, and "π" is the repository that's what a Monad is

SolathPrime
Автор

It's like saying an axe is more powerful than a hammer lol... flatMap and map are just two tools for different purposes.

kungfooman
Автор

正想說怎麼這麼久沒講 functional programming,這不就來了嗎

銅學-ke
Автор

Sadly, even though I went to the same University that people who make PayPal in YouTube went to, if I accidentally click off of this video on the YouTube app for Android, they don't have a functionality for undo so I have to watch ads and I have to manually find my position in the video after searching for the video in my watched history, but they'd never hire someone like me or listen to my advice. These are basic user interface rules which were defined since the 1980s and 90s but YouTube forces you to use their app even though they can't provide basic interface functionality for even a simple user.

TimJSwan
Автор

It was hard to keep awake with teh monotonous AI-style voice (not sure if actual AI or just Spock though). But the content was certainly worth it.

Oktokolo
Автор

Original paper would be Moggi, before Wadler ...

pmcgee
Автор

and yet another video that fails to explain what a monad is (to me). 😟

klaus-udokloppstedt
Автор

sorry, I still don't get it lol. good thing is I want to learn Haskell anyways

ゾカリクゾ