25 ms·
To have an idea of monads being sequential, think about a JS Promise: promise.then(...).then(...).then(...)... Promises are (almost) monadic, and the chain
by nine_k 2y ago
To have an idea of monads being sequential, think about a JS Promise:
promise.then(...).then(...).then(...)...
Promises are (almost) monadic, and the chain is sequential. You can't make it parallel, and that's the point: monadic binding represents sequential computation, aka "the semicolon operator".
To have an idea about applicatives being parallel, think about a list of functions, and a list of values; each function would be applied to a corresponding value, resulting in a list of results:
results = []
for ix in range(functions):
f = functions[ix]
x = values[ix]
results.append(f(x))
It's pretty obvious that you can do each f(x) in parallel and in any order, instead of the sequential code above.
(Why would one care about this all? Because many daily things are functors, applicatives, and monads, e.g. a list is usually all three.)