@Amos Royal yea, have been using flixzone} for years myself :)
@daytondeclan35673 жыл бұрын
@Amos Royal yup, been using Flixzone} for months myself :D
@cuadernoazul59588 ай бұрын
Wow man you are the first content creator who really explains IO monad clearly and rigouroly without philosophical bullshit. Congrats!
@kozmicluis25526 жыл бұрын
I love it everytime I hear eye-oh monahd
@peter627095 жыл бұрын
This is the first explanation of a monad that actually made sense to me, and also the first I've come across that explained it as changing the state of the world. It seems a lot simpler now. Thank you!
@Tsoding5 жыл бұрын
This is not an explanation of a monad. This video is about the *IO* monad specifically. There are many different monads out there. And they all do different things.
@tricky20146 жыл бұрын
You are really good at explaining things in an accessible way. Also your pacing and tone of voice is very good.
@leonardomoraes65055 жыл бұрын
HEY, that's just state monad with the state being the outside world!
@anuraghooda84394 жыл бұрын
"RealWorld" to be precise
@DeH4er15 жыл бұрын
Хорошая работа, спасибо за видео!
@kahnfatman2 жыл бұрын
THE BEST IO Monad explanation - EVER! This is PURER than gold. Btw, I love your wtf transformer.
@ivanperevezentsev73955 жыл бұрын
Perfect, finally I understood the IO monad. The explanation with world transformers really makes sense.
@GerinoMorn3 жыл бұрын
I went from "what is IO monad" to "I probably can implement it from memory" in 30 min. The guy is amazing truly.
@Bravo-oo9vd5 жыл бұрын
"Monad is just a monoid in the category of endofunctors, what's the problem?"
@anticipayo4 жыл бұрын
Duuuhh!
@EidosGaming4 жыл бұрын
"You just made these words up!"
@himselfe6 жыл бұрын
First 15 minutes: Hey, Haskell doesn't seem that bad! Might try learning it... Last 20 minutes: Why!? Seriously... WHY!?
@Tsoding6 жыл бұрын
IT'S A TRAP!
@yagarf95102 жыл бұрын
My first Haskell book just came in the mail and I’m super excited to explore the world of FP. I decided to pause the video until I learn more Haskell but I will surly come back and rewatch after playing around with Monads on my own!
@РайанКупер-э4о3 ай бұрын
So, had you rewatch it?
@superrritschy4 жыл бұрын
Damn. This is the best explanation of IO Monad I’ve ever seen.
@sho3bum6 жыл бұрын
This is exactly how brian beckman explained monads but instead of using the world as an universal set he used monoid, this is a pretty nice example, I loved it!
@andrew_ray5 жыл бұрын
I knew it would be `unsafePerformIo`. That weird behavior of performing side effects in the middle of printing a supposedly pure value is a classic example of the issues of `unsafePerformIo`.
@fyradur4 жыл бұрын
This is one of the best videos I've ever seen, regardless of genre for the last 10 years of watching KZbin atleast 2 hours a day.
@arshadpakkali3 жыл бұрын
Jokes on you im watching 5 hrs a day and still confused about monad but this video actually made some things work on my brain
@cranknlesdesires4 жыл бұрын
Tonight on CN9 News; Russian Hacker replements reality in program to print names, solves science in the process; are jackets really used to keep you warm or are they a Chinese marketing ploy?
@vnshngpnt3 жыл бұрын
Brilliant video man, very good :) It's a very interesting approach to explain monad (well, just IO monad) from a different perspective, from top to bottom so to speak, without first explaining functor and applicative. Inspires to keep learning Haskell and FP
@hansschenker4 жыл бұрын
Imperative programming is vertical: statement after statement! ≡ functional programming is horizontal: funtion -> function - - -
@EidosGaming4 жыл бұрын
I just wanted to know about input output now I have an existential crisis on whether the world is just a state or not
@exciting-burp2 жыл бұрын
I'm going to have to watch this 3 more times, but I this video have have been the furthest I have gotten in terms of understanding monads.
@duanwen46484 жыл бұрын
Dude, love your channel, please keep doing it
@Diamonddrake10 ай бұрын
If a pure function is a function that always returns the same result for the same input then preventing the possibility of passing the same input twice makes it effectively pure... But also… what?
@b_two Жыл бұрын
conceptualizing side effects as a localized illusion in a pure global function is genius
@anticipayo4 жыл бұрын
A perfect Haskell program is an inEFFECTive program by definition
@juang.garcia7390 Жыл бұрын
Absolutely brilliant. You've won a subscriber
@Tomyb152 жыл бұрын
I really liked this approach to understanding the IO Monad. However, I'm a bit confused on the aspect of calling the diy monad "pure" in the abstract when we know that the function readStr doesn't always return the same result from the same input, given that what the function reads from stdin isn't part of its "inputs".
@fredoverflow2 жыл бұрын
stdin is part of World
@christophhofer303 Жыл бұрын
Well its pure because it always returns the same thing given the same world. The „world“ is you sitting in front of the computer and typing into the console.
@redumptious25443 жыл бұрын
Others: Learning math from some Indian dude Me, an intellectual: Learning Monads from some slavik dude Great tutorial, thank you 👍
@IvanNIlic4 жыл бұрын
28:09 seconds of pure triumph (as the shit flies towards the fan) . oh, inverted World!
@gerardgauthier48766 жыл бұрын
I thought Martin Odersky said "The IO monad does not make a function pure. It just makes it obvious that it's impure.".
@Tsoding6 жыл бұрын
For that I have only one thing to say: 6:31
@gerardgauthier48766 жыл бұрын
@@Tsoding@ I find Haskell and Java suffer from the same problem. They take a limited(rigid) paradigm and shoehorn unlimited problems/solutions into it. A monad is a beautiful/simple design pattern that becomes 'almost' incoherent when its applied to state in a 'pure' system.
@leftaroundabout6 жыл бұрын
The comparison with Java doesn't fit, but you could perhaps say this about Smalltalk, which (unlike Java) is a purely-OO language. If you design the fundamental principles of a language rigidly around a paradigm, then it changes the very meaning of what “programming” is. From that point it's nonsensical to complain you can't do mutation etc., because mutation is not a concept that _can exist_ - or in Smalltalk, standalone functions aren't something that can exist. Java with OO, or F# with functional (or Scala with both!), give you a weird compromise: they are in principle imperative, but then impose restrictions on how this imperative code is supposed to be structured. “Patterns”. But that's missing the point IMO. In particular a monad is not a design pattern, it's a _property_ of some higher-order type. It turns out that the State-Of-The-World updating that needs to be done to model imperative in a pure-functional language fulfills the property of being a monad. But in an impure language, there's actually no way to prove a property like that, so F# and Scala don't have monads. (Strictly speaking, you can't prove it in Haskell either because of ⊥, but in “total Haskell” you an prove it.)
@gerardgauthier48766 жыл бұрын
@@leftaroundabout@ I guess the jury is still out on - design pattern. en.wikipedia.org/wiki/Monad_(functional_programming)
@leftaroundabout6 жыл бұрын
@Gerard you should know not to quote Wikipedia as an “authorative reference”, right? Quote Eric Lippert directly. Unfortunately, he doesn't really understand monads (as variously proved online), he's just good at using _the translations of particular Haskell monads into imperative/OO languages_ - which can be pretty useful already, no doubt, but it's still little more than cargo-cult-science. What a monad really is is explained in Wiki's category theory article on the subject. en.wikipedia.org/wiki/Monad_(category_theory) This is not to say that one must understand all of that, certainly not the part about adjoint functors, to use monads. You're good if you know the monad laws and how to prove them within the pure subset of your favourite language. But you should keep in mind that there's more to monads than that.
@justinroughley1515 жыл бұрын
Really great explanation of IO Monad - Thanks
@vorname14853 жыл бұрын
Me being asked: "What are all those red buttons?" Me: "side effects" Me being asked: "Is the app finished? I'v started it but nothing happens" Me: "Oh, you wanted it with side effects?"
4 жыл бұрын
Now for me is completely clear... I have to study more.
@thymiosdouvis5754 жыл бұрын
"What is my name btw?" hahahaha
@DanDart4 жыл бұрын
Side effects make you forget your name.
@Zorgatone4 жыл бұрын
Name of the outro song?
@markuspfeifer84735 жыл бұрын
What if I want to have two buttons - one button starts a lengthy operation and the other button can abort it because it takes too long? That sounds quite hard to me...
@deidyomega5 жыл бұрын
Yeah... in python, js or any oop language that's super easy... not sure about haskell though
@PacificBird2 жыл бұрын
@@deidyomega Monads in Haskell have a lot of extra functionality baked into them that allows for concurrency and stuff, so this isn't a problem.
@nekoill3 жыл бұрын
Is it just me, or functional programming languages are very distinctively similar in syntax? Elixir, Clojure, Haskell, Elm as well (I think)... Only Lisp is its own beast, E-Lisp specifically.
@fredoverflow2 жыл бұрын
Clojure is a Lisp
@valentjedi6 жыл бұрын
Surprisingly, I kinda get it and feel a bit "whoa"! Cool, really great video! Btw, I assume that underneath this nicely done illusion of a pure environment lies highly mutable conglomeration which is built in C. Otherwise, this whole thing would've consumed all memory really fast. Am I right?
@alexeykutepov37676 жыл бұрын
I don't know the specifics of the IO implementation, but IO itself is defined in terms of something called `State# RealWorld` github.com/ghc/ghc/blob/2c959a1894311e59cd2fd469c1967491c1e488f3/libraries/ghc-prim/GHC/Types.hs#L187 the value of which occupy 0 space: stackoverflow.com/a/32673064/2951870
@sbditto855 жыл бұрын
if you are referring to the fact that Haskell has a runtime then yes. Often people describe it as your Haskell program is a recipe that the runtime "chef" creates (runs) for you
@guidof61164 жыл бұрын
Well, I guess changing the world wasn't that hard after all
@dvtt3 жыл бұрын
Is there a link to the code ie - github?
@aziz0x00 Жыл бұрын
First time I understand it!! Thanks a ton!!!!
@joshbassett8 ай бұрын
Mind blown 🤯
@Jere1515 Жыл бұрын
Thanks for the vidéo, it helps to understand better IO Monad. Is the world concept really used? Or is it just a "thought experiment"? Do you know if ZIO or IO from Cats Effect in Scala are implemented like that???
@sebastiangudino9377 Жыл бұрын
In clean, yeah! But you cannot "touch" the world. And you cannot clone it either, since that's kinda the point of uniqueness typing In Haskell. The world is "There", but you cannot touch it either. The IO monad IS the world, when you input from the user for example you cannot just take the value out of the IO monad (The world). You have to keep it wrapped by the world's state. And you just send it the instructions to make a new world where your side effects will be executed. And get a new world as a result As you can see, the world is NOT accessible (We cannot touch the IO monad), which is GREAT because things are still inmutable. While also actually producing side effects by making those changes in the world manifest in your screen And of course since we don't need to access the "world". There is no reason for your computer to actually store the entire world, so the compiler optimizes it away 😉
@Jere1515 Жыл бұрын
@@sebastiangudino9377 Thanks for the answer :) And what about IO executed in parallel? 😅
@sebastiangudino9377 Жыл бұрын
@@Jere1515 FP is implementation dependant (So there is no "Other thread" as far a the Haskell type system is concerned). But in general each Thread would be running a function that takes an IO and returns an IO. Then a function (Like ForkIO) would make sure that, while they do happen at the same time, the world is still a just one world. And it does that by making sure the results of the functions gets "Applied" to the world in the correct order (So if for example you need to process two files at once and then concat the results and print them, haskell will make sure you are still using a function that gets the file from the world, then both files will start to process, but then when BOTH are done we will tell the world that file one is processed and a new world where ONLY that file is processed will come out, and then to that one we apply the already computed result of the other file and then we can concatenate and print them as if there was never a fork (Since we never cloned the world) ) I'm not sure if my explaination is more confusing than helpful. But I hope it helped. As far there are never two world everything will still be "inmutable" to Haskell. That makes multiprocessing in Haskell a blessing and a curse. Since there is a little bit magic going on behind the scenes that makes it kinda hard to know WHAT exactly the code is doing physically. But I guess that's kinda the point of declarative code
@arcuscerebellumus87978 ай бұрын
Ok, I sorta' get the "how" (not really)... but, WHY?
@bhavyakukkar4 ай бұрын
0:18
@DanDart4 жыл бұрын
4:59 conspiracy
@hahas952 жыл бұрын
Thank you for this video!!!
@andreffrosa4 ай бұрын
I think it would be cool to now explain monads but instead using an imperative language, like C.
@agcouper2 ай бұрын
Check Bartosz Milewski videos, he does exactly that.
@DanDart4 жыл бұрын
by 8:46 "world" has no meaning
@johannbauer28635 жыл бұрын
Wow! This video is great! ^^
@junderfitting87173 жыл бұрын
great video. I'm confused with "side effect", I've browsed the comments at the very bottom, but didn't get the answer.
@ea_naseer2 жыл бұрын
side effect is something additional your function does. For example a reverse function should reverse an array but it could also change the original array. Changing the original array here would be a side effect of reversing.
@arnejarek33086 жыл бұрын
keep up the good work
@LeoOno4 жыл бұрын
4:40 "you see what side effects do to you ?" lol xD very awesome video ! i'm trying to study haskell and please can you explain this part again for me? readStr :: World -> (String, World) can it be considered pure function ? i mean, i have the impression that even passing the same World, it can return different values ... am i misunderstanding something ? thanks for this amazing video :)
@nicolasmarcora93304 жыл бұрын
Imagine that by World you're freezing time and capturing the exact state of the world as it was at that moment. If you print "Hello!" to it you get a new World where "Hello!" was said. Now you have two Worlds, the initial one, and the one you've printed to. If you keep printing to the initial World, you wouldn't be changing it, but creating multiple new Worlds with "Hello!" printed on them. It's confusing because you know that's not how things work in the real World. But it's a nice abstraction to keep things pure within Haskell while doing useful input and output.
@LeoOno4 жыл бұрын
@@nicolasmarcora9330 first of all, thanks for your reply :D In the case of IO print, i could get the idea of 'world' + String argument returning the new 'world' with String printed to it, it's all immutable, so in this case i can see it's pure. But when it comes to IO user input, i'm still confused because i have the impression that passing 'world' as argument, it returns 'world' with some arbitrary String, so in this case how we can affirm this is pure ?
@kirill_itheo4 жыл бұрын
Maybe its based on the idea that By knowing the state of the world we know what the user's input is going to be.
@mrmimeisfunny Жыл бұрын
@@LeoOno The World (which includes the console window) gives you the input string. An alternate world where a different string was typed will get you a different string and a different world.
@TheOlian046 жыл бұрын
So a monad is a pure function that takes and returns a world-state?
@Tsoding6 жыл бұрын
Yeah, I believe it's a pretty good way of thinking of it. Of course internally the actual IO is probably just a bunch of hacks, but on the outside it's a pretty good way to fit side-effects into a pure functional language. P.S. Keep in mind that we are talking specifically about IO monad. Not monads in general. There are many monads. And not all of them are about modifying real world states.
@monnef6 жыл бұрын
I believe monad is rather a type, which has an accompanying operator (pure function - bind) which transforms the world.
@ViktorKronvall6 жыл бұрын
No, the IO monad is a monad that hides the world type which is used by the Haskell runtime similar to what was shown in this video. A monad is a much more abstract concept. A monad (in Haskell) is some data type that has three functions defined for it. Let’s call this data type `x`. The three functions are then: 1. fmap :: (a -> b) -> (x a -> x b) 2. pure :: a -> x a 3. (>>=) :: x a -> (a -> x b) -> x b What is more there are some laws that must hold for these three functions for the data type to actually be a monad. 1. fmap f . fmap g = fmap (f . g) 2. fmap id = id 3. pure x >>= f = f x 4. m >>= pure = m 5. (m >>= f) >>= g = m >>= (\x -> f x >>= g) where id is the identity function implemented as `id x = x`. It just returns what it’s passed. If you can prove those five properties you have a monad. If you are interested I can show you the proof for these properties for WorldM.
@beforth5 жыл бұрын
A monad is a type within a context, a function to wrap a value of the type into the context, and another function to apply a function to a value of that type inside the context. Plus in haskell you have syntactic sugar (do notation) to avoid explicit nesting of functions, so you don't have to count parens. But it's easy to mix both concepts and get confused.
@detaaditya62374 жыл бұрын
You can't spell haskell without hell
@jit_rs5 жыл бұрын
Отличное видео Я не до конца понял почему тип оператора (>>=) именное такой, какой есть, но в целом очень помогло понять как пользоваться IO и как оно устроено
@expurple Жыл бұрын
(>>=) :: m a -> (a -> m b) -> m b У нас есть две функции трансформации мира, которые мы хотим скомпоновать: `m a` и `m b`. Помимо собственно трансформации мира, эти функции ещё потенциально возвращают некоторые значения `a` и `b`. Скомпонованная функция будет возвращать последнее значение в цепочке, поэтому у финального результата тип `m b`. Тип `a -> m b` возникает из-за того, что у нас вторая трансформация может _зависеть_ от результата первой. Здесь например второй >>= компонует `readLn :: IO String` и `case :: IO ()`, значение которого зависит от name (результата readLn): whatIsYourBranchName :: IO () whatIsYourBranchName = putStrLn "What is your name?" >>= \_ -> readLn >>= ame -> case name of "Alexey" -> putStrLn ("I love you, " ++ name) _ -> putStrLn ("I hate you, " ++ name)
@expurple Жыл бұрын
For English speakers: here I'm explaining the signature of >>=. In case you're interested, my comment seems to be Google-translatable just fine
@AlexLexus422 жыл бұрын
Круто! Знаю что ты забросил писать на хаскеле, но я уверен, многие бы хотели увидеть haskell стримы от тебя!
@AdamSchelenbergCom6 жыл бұрын
If you draw a monad how it would look like?
@softwareminimalist6 жыл бұрын
Like a railway :)
@Pradeep19896 жыл бұрын
@@NazariiBardiuk Thanks for sharing this link. This is super useful.
@gbcr095 жыл бұрын
Great video!
@0xlkda2 жыл бұрын
Im still not get it.
@TRex-fu7bt Жыл бұрын
I want that color scheme. That yellow pops.
@bhavyakukkar4 ай бұрын
Gruber darker (emacs theme is on his github and people have also ported it to vim/vscode)
@aziz0x00 Жыл бұрын
Haskell is just so amazing ❤
@freaking11223 жыл бұрын
Well explained!
@niikurasu28552 жыл бұрын
Bro lives in the backrooms
@rnoro11 ай бұрын
What stops you making videos? It's a shame there is no update in this channel XD
@bhavyakukkar6 ай бұрын
he uploads videos very often on his other channel (most of which are vods of 2-3 hr streams where he implements a new idea in whatever language)
@mechmaker93465 жыл бұрын
Very good video! About unsafePerformIO: 1.it,s bad,because haskell hasn't got stability in evaluation,and monads is only thing,which helps you. 2.It,s not declarative,to have dirty code in pure,it brings imperative order in declarative code.
@nathaaaaaa5 жыл бұрын
Nah, I dont wanna learn relativity now
@vertie20904 жыл бұрын
No hello world in Haskell for you then ¯\_(ツ)_/¯
@sidjoosin65495 жыл бұрын
input and output - are not "side effect" . if your your function takes arguments and prints them on screen, like printf() or console.log() , this is not "side effect" of this functions, this is pretty strait effect, theese functions are made for output some args. Side effect - is when your function "add()" write something on screen, or return to the world something, but sum of args
@deidyomega5 жыл бұрын
io is def a side effect
@sidjoosin65495 жыл бұрын
@@deidyomega so function without io is pure? i think answer is obvious. there is no function in the world that don't takes input and don't returns output, who gives input args -- another fntion or user -- inside the function it is no difference. as well as it is no difference where it returned value -- to another fn or to your screen, or both
@deidyomega5 жыл бұрын
@@sidjoosin6549 You can take an input and return an output without using print (or equivant) python example: def pure_add(a, b): return a+b def inpure_add(a, b): print(a+b)
@Bravo-oo9vd5 жыл бұрын
I think that "a side effect is something that a function doesn't say it's doing" might be a good way to put it
@xdman2956 Жыл бұрын
28:43 Why did it print "(()" before "What is your name" ? btw great vid, Im the happiest one could be after filling in the >>>= return type and body myself despite not having written no haskell ever :) .* It is unreasonable how transferrable are some math skills to writing in a language I only saw type definitions in beforehand. (Well, being freshly after kzbin.info/www/bejne/m2fXiH16atZrq9k helped with the monad return type and knowing what was going on - that we were writing flatmap :) Gosh, this 2-vid combo is the greatest to understand the topic in detail, if you know/broke your head for a while over what monad is, but without type definitions beforehand (all the "adding logging to functions" is a monad, "Option" is a monad like in this vid: kzbin.info/www/bejne/eWPaZWinh8hml7c and some by A Byte of Code). *Well, gotta admit I wrote composition explicitly as w->uncurry(f)(wt(w)) instead of uncurry(f) . wt (which I hope is too - syntactically, I mean). I could've thought of composition after the vid I mentioned and in general if I was more aware that it has to be in this language, but before you wrote it in its symbol could be ∘ for all I knew :)
@xdman2956 Жыл бұрын
Oh, I think I see. I stopped immediatetly when I saw it, and then also expressed my gratitude. Turns out is not so mysterious just a few seconds later
@DjLeonSKennedy5 жыл бұрын
Жестко
@WomboBraker Жыл бұрын
difficulty to write actually useful programs with fp paradigm is long lasting major problem hahahahahaha
@yungclump2 жыл бұрын
Seen.
@goosygoose25176 жыл бұрын
I made a snippet pastebin.com/z6GHKL8F. How the returned value from printStr (World) is the new state of the world. It is the same data constructor that was passed as an argument to the function. It's the same value, - World. And if you meant that every time you write data constructor World you get a different World (in that instance of time let's say), then that value (World) in itself is not pure and is against what a value is. 5 = 5. World = World.
@Tsoding6 жыл бұрын
I lied
@GerinoMorn3 жыл бұрын
Why am I not surprised that the best Haskell tutorial I've ever seen is done by a Slavic brother... Amazing job!
@SolathPrime Жыл бұрын
branchWorld :: World -> (World, World) I've tried the same thing in python it's behaviour is undefined
@sh_zik4 жыл бұрын
World changese in time so....
@ethanpaulmorgan51236 жыл бұрын
Dad
@first-thoughtgiver-of-will24563 ай бұрын
In Rust functions are third world citizens (Fn FnOnce FnMut)
@Chemaclass4 жыл бұрын
So easy going hahaha
@venustheplanet82083 жыл бұрын
I wuv yu
@androth15025 жыл бұрын
i'll go with "you just switch to a good language."
@boku004 жыл бұрын
This is so illegal.
@nincako5 ай бұрын
What is side effect? Since it is not stated, I am stopping this explanation. downvote!