3 ms·
i'm with the gp. i guess another way i think about it (which might be wrong, please tell me) is that with monads we can talk treat something like pipe as a pure
by convolvatron 5y ago
i'm with the gp. i guess another way i think about it (which might be wrong, please tell me) is that with monads we can talk treat something like pipe as a pure object, even though whats its carrying is decidely not
- camgunz 5y agoYup, exactly. It's basically like if you have a bunch of simple arithmetic functions: half(x) double(x) triple(x) you can easily do things like: double(half(triple(13))) Or a la pipes: triple 13 | half | double But now what if you want to print something in `half` without a global? Well, I guess it's half(x, printer) now. Hmm and now `triple` has to carry that around too, so it's triple(x, printer). Well, that makes me think everything gets a printer, so it's double(x, printer) now too. Well, printing is cool, but now we're a real company and real companies log everything. I... guess we're making new functions? half_log(x, logger) and triple_log(x, logger) and double_log(x, logger). And... new pipelines? Ugh. At this point you might be thinking one of a number of things: - Are globals really that bad? - Can OOP fix this (dependency injection, builders)? - Surely there's some kind of framework for this. And if you're a functional programmer who's super not into globals or OOP, you might start seeing the appeal of #3 there. Et voila, a whole bunch of functions that handle this "pass an extra blob into your pipelines" thing.