The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
Map says I apply a function to every element of the list.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
Well, so it has type A to B to list of A to list of B. If you want to apply an IO performing function, so the function you're applying has type like int to IO of char, you could map that over a list, but you just get a list of IO of chars.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
That hasn't done any IO yet, right?
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
You want something that says, take a list of I-O chars and perform those actions one at a time.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
So I want a function that goes from type list of I-O char to I-O of list of char, right?
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
And you might want to perform all those actions top to bottom or maybe bottom to top.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
Who knows?
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
That's what this function of type, you know, so yes, so you could do it in various ways.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
So sometimes it gets in the way, right?
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
You say, oh, shit, you know, can't I just use map?
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
Well, in Haskell, no, sorry.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
You're going to have to do a little bit more work to tell me in what sequence you want your effects to happen.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
Because by default, Haskell does not specify sequence.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
So adding monads to control effects does get in your face a bit.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
And that's the tax we pay.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
In effect, that's part of the big experiment that Haskell is doing, is to say, suppose we up front say we're willing to pay that tax.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
How many followers can we get?
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
I will note that monads have infected quite a lot of other languages.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
F-sharp is definitely called by value impure language, and yet F-sharp had these workflows that were definitely monads.
The Peterman Pod
Co-Creator of Haskell: Functional Programming, Thinking in Types, Useless Languages | Simon Jones
Monads have appeared in Scalo and in many other languages.