5 ms·
Looks like a new hell!
by shakiba 10y ago
Looks like a new hell!
- kccqzy 10y agoHow is this a new hell? This is some elegant, mathematics-derived abstraction.
- pron 10y agoElegance is in the eye of the beholder, and being mathematics-derived says nothing of its suitability for direct use by humans. Gödel numbering is also "mathematics-derived" but few people would regard it as particularly elegant or useful (it may be elegant in the mathematical purpose it serves, but not for engineering).
- scribu 10y agoIt will turn into a hell because JavaScript lacks Haskell's strong type system. The tooling will not give you early warning if you pass a plain function into a construct that expects a promise etc.
- homami 10y agoThat's very true. But on the other hand dynamic typing is what enables us to play with JavaScript and re-create many concepts from FP in plain JS. This is not easy in many strongly typed languages which their type system falls short of Haskell's (that supports ADTs, kinds, recursive types, etc.).
- scribu 10y agoYes, dynamic typing allows experimentation. But just because you can make JS look like Haskell doesn't mean it's the most effective way to get stuff done. You'd be better off writing Haskell and transpiling it, IMO. Note that I'm talking about writing an entire application in this style, not just sprinkling categories here and there.
- joostdevries 10y agoI'm a static types kindaguy. So I've rewritten some of this code using Typescript to see what that looks like. https://github.com/joost-de-vries/typescript-ramda/blob/master/src/typescript/Callback-monad.ts https://github.com/joost-de-vries/typescript-ramda/blob/mast...
- cutler 10y agoThis killed it for me: class Callback ..... this.then = g => new Callback(callback => Can't we just keep OOP out of FP?
- homami 10y agoUsing class enables us to chain instances naturally in JS syntax, especially because JS lacks infix functions or custom operators. o1.then(f).then(g).run(cb)
- BinaryIdiot 10y agoYou can avoid the class syntax here and write a function to return the same if you prefer.