|
|
|
|
|
by yoz-y
3981 days ago
|
|
Every time I see one of the monad articles I think "this looks like promises, except it has a nicer syntax in Haskell". Is there any reason to use monads in (let's say) Javascript rather than promises? Are there any performance gains? |
|
A little while ago there was an article (https://news.ycombinator.com/item?id=9907435) which suggested code like
is simpler and better than or something like that. In a certain sense this is objectively false as the second one uses fewer features than the first (a statement we can make formal using monads, but that's unrelated). I'd argue this is doubly true because whenever non-linear flow control begins to be used pervasively it is hard to know what code will be executed and under what conditions. With nesting at least these conditions are obvious.In any case, we can solve this conundrum through the existence of an Option or Maybe type which encapsulates the imperative behavior of short-circuiting failure directly and limits it's scope.