Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

To give a brief "explanation", look at the type signature of a callback-based API:

  readThisFile: string -> (string -> void) -> void
Usage:

  readThisFile('foo.txt', result => ...)
You have a double void here. Which is the hand-wavy justification as to why callbacks don't compose. On the other hand, a promise's value is Promise<actualTypeOfValue>, which you can pass around as data without asking the other end what it wants to do with the value (aka decoupling). You do have the imperative action at the top to kick the whole chain into motion, but the intermediate stuff are most of the time side-effect-free.

Hopefully that was clear enough to see that passing actions around is akin to controlling the flow with e.g. if-else, and that passing data around is declaring how your tubes/rail tracks/whatever analogy for monads are constructed, aka data flow.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: