3 ms·
I think his choice of Monads to explain this phenomenon was a good one, speaking as someone who does not understand Monads but occasionally glances at tutorials
by jimbokun 18y ago
I think his choice of Monads to explain this phenomenon was a good one, speaking as someone who does not understand Monads but occasionally glances at tutorials about them.
My thought process about those tutorials is always "explain to me why I should care." I get that the problem that Monads try to solve is that functional programming demands that a function always return the same value given the same arguments, and that makes I/O impossible, but you can't write real programs without I/O. So Monads are an attempt to find a loophole.
Well, what if the answer is just that functional programming is just not a good way to write programs in the first place? Sure, functional programming has lots of properties that are appealing, but if you need to do intense mental gymnastics just to get "print 'Hello World'" is it actually worth it?
To me, that is the point from which a "Monad tutorial" should begin, and then provide concrete examples showing that with Monads, sticking with functional programming is better than just giving up and using Python.
- olavk 18y agoIO handling is just one of the uses of monads in Haskell. List comprehensions (like in Python) are another use. They are also used for parsers, asynchronous programming, exception handling and continuations. I wrote a answer on stackoverflow which tries to explain monads with some practical examples: http://stackoverflow.com/questions/44965/what-is-a-monad#194207 http://stackoverflow.com/questions/44965/what-is-a-monad#194...
- jimbokun 18y agoThat was very good! Nice examples. You also do a good job summarizing why IO is hard in Haskell, in that you need to understand a lot about the language to understand how IO works. I guess it's up to the individual to decide whether FP is worth getting past that initial hump.
- eru 18y agoI found the way Clean deals with IO simpler to learn than Haskell's Monads. (But then, I learned Clean before I learned Haskell. They have a nice Jump-n-Run in their example directory.) Clean employs linear logic, that is you can only have one copy of the 'World' in your program. Look at the printing function as an example: It takes your old World and transforms it into a new World, that has something printed to the screen. Of course such a view of the outside world is quite autistic. But it works as long as you manage to have only one World around in your program. The IO Monad in Haskell could have been implemented with linear logic. (And in GHC it is, I think.) More information at http://homepages.inf.ed.ac.uk/wadler/papers/monadsdeclare/monadsdeclare.ps http://homepages.inf.ed.ac.uk/wadler/papers/monadsdeclare/mo... The original papers are surprisingly accessible. I prefer them to the tutorials.