Monads: From Web 2.0 to Hardware Drivers
well-typed.com
Monads: From Web 2.0 to Hardware Drivers
1–8 of 8 posts
Re: Monads: From Web 2.0 to Hardware Drivers
#2Just to nit pick... Passing a callback to a function as an argument doesn't magically make that function asynchronous, in JavaScript. For example:
var block = function(callback) {
while(true) {}
callback();
};
Only those functions that are implemented asynchronously (such as Node.js' fs.readdir, from the article's example) will actually be asynchronous.Re: Monads: From Web 2.0 to Hardware Drivers
#3Re: Monads: From Web 2.0 to Hardware Drivers
#4Re: Monads: From Web 2.0 to Hardware Drivers
#5The Javascript example kind of confuses the solution with the problem. The convoluted syntax of the 'callback-hell' is the problem. Monads does not solve this problem, rather the use of monads leads to that kind of syntax. The solution proposed for the syntactic mess is Haskells do-notation. Do-notation is not monads, rather it is syntactic sugar to make the use of monads bearable. Something like lisp macros would be…
Re: Monads: From Web 2.0 to Hardware Drivers
#6The Javascript example kind of confuses the solution with the problem. The convoluted syntax of the 'callback-hell' is the problem. Monads does not solve this problem, rather the use of monads leads to that kind of syntax. The solution proposed for the syntactic mess is Haskells do-notation. Do-notation is not monads, rather it is syntactic sugar to make the use of monads bearable. Something like lisp macros would be…
But lisp macros don't give you the strong type safety properties that Haskell gives you with monads. The most general solution is not always the thing you want. Sometimes you want the solution that gives you the strongest guarantees about the potential behavior of code.
Re: Monads: From Web 2.0 to Hardware Drivers
#7That javascript code is awful (and yet probably typical). There are three asynchronous readdirs that don't depend on each other (and should be able to run parallel) which now depend on each other and any asynchronous benefit is lost. Maybe haskell is smart enough to run them in parallel. For javascript, Promise.all would be better and avoid the pyramid of doom. Or, just use synchronous code for your, well, synchronou…
Re: Monads: From Web 2.0 to Hardware Drivers
#8> Functions that take a callback argument are called asynchronous functions. Just to nit pick... Passing a callback to a function as an argument doesn't magically make that function asynchronous, in JavaScript. For example: var block = function(callback) { while(true) {} callback(); }; Only those functions that are implemented asynchronously (such as Node.js' fs.readdir, from the article's example) will actually be a…
Using callbacks means giving up control of when things will happen. The fact that it will actually happen very soon is out of the question.