3 ms·
I would like to try to do something like that! Do you have thought about how a syntax like "do" would look in JavaScript?
by olavk 16y ago
I would like to try to do something like that! Do you have thought about how a syntax like "do" would look in JavaScript?
- jhpriestley 16y agoProbably a lot like javascript. with_monad(foo){ var x = bar(); baz(x); } where foo includes a definition of bind and return (return should be renamed, there is already a return in js). Subcalls like baz(x) would be interpreted within the same monad. Basically you would just make semicolon a function with dynamic extent, rather than a language builtin. I don't know if it would be possible to monadize functions which use break, continue, or return. While and if would have to be special cased.
- olavk 16y agoBut wouldn't that require that all calls inside the with_monad block is of the same monad type? Wouldn't the syntax need a way of distinguishing between monadic and non-monadic operations (like using "let" rather than "<-" in Haskells do-syntax)?