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

My friend told me recently that he invented monads in Javascript:

  result = monadicObj
         .action1(arg)
         .action2(arg2);
I told him that he needs variable binding operations for fully fledged monads:

  result = monadicObj
         . x <- action(arg)
         . y <- action2(x,arg2)
         . action3(x,y,arg3)
         . return (x+y);
Otherwise, his invention is much more like Applicative, because we cannot pass values between actions.

So here it is: monads are just objects with overloaded and extended "." operator and with special function "return" that modifies object (in accordance with object meaning) and returns it's input value unchanged. That new operator allows us to bind return results if we want so. Overloading of "." allows us to implement various interesting operations - passing state, executing optional computations, executing non-deterministic computations, probabilistic computations, etc.

You incapsulate the meaning of computation inside object, so you can pass it to some evaluator without that evaluator knowing that you pass him non-deterministic computation instead of monte-carlo monad or vice-versa.



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: