Simon Peyton Jones
π€ SpeakerAppearances Over Time
Podcast Appearances
Okay.
So do lets you combine IOU performing computations together.
So print3 has type IOUnit.
It does some I-O, namely printing free.
Get char has type I-O char.
It does some I-O, namely reading a character from standard input and returns a character, right?
Notice that's different from just char.
So, you know, quotes X quote, that has type char.
It's just the character pure, right?
Get char, the IO performing operation has type IO char, it does some input output and returns a character.
Okay.
The do notation lets you combine together IO performing computations.
So if you could say do, and then you say X left arrow get char, semi-colon, put char X,
then that x left arrow get char that says run the get char computation and get me the character, call it x. The put char x says run the put char computation to put x and we combine them together with a do notation that combines two computations to make one IO-performing computation.
But these things are completely first class.
That's what's new about monads compared to just make it into C.
X left arrow, get char semicolon, put char X. That's a computation whose type is IO unit.
Let me give it a name.
So I can say let foo with type IO unit equals that do.
Now I can pass foo as an argument to something.