-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception handling examples #36
Comments
Now that probably won't do what you want because you will have an function map(lambda) { return function (source) {
return function continuable(callback) {
source(function (err, value) {
return err ? callback(err) : callback(null, lambda(value))
}
}
} } Note what we are doing here is saying that an async data type is a boxed thing that is either an This means when you use it like ajax(...).map(JSON.parse)(function (err, json) {
// handle err here if exists else json
}) You can handle the error there and then. TL:DR; All values inside a boxed asynchronous thing are of type The specific answer to |
It should be noted that in promise land the function for consuming a promise is called |
@Raynos: I'm not really sure where all of that is coming from. Most (all?) promise implementations I've seen conflate the Either and Future together into a single type, so you never deal with an Either directly. I'd certainly prefer to see some kind of Also, all monads are automatically functors. First I've heard of a @jden: The error part of a Promise isn't exposed by the Monad interface. Monads only explicitly deal with the success path, though a correct Monad instance would necessarily have to propagate the error internally. Most promise libraries provide some kind of It's also been shown that if you only have separate |
@Twisol promises-aplus/unhandled-rejections-spec#5 If you were implementing lazy promises the invocation of Promises do conflate |
I see. Lazy promises are different from non-lazy promises however, and if we're just talking about promises in general, you can't rely on the existence of
The key phrase here is "under the hood" - no promise library I know of exposes the internal Either representation. I know for a fact that when.js has an ad-hoc Either in its source code, but it's an explicit goal to make sure that never leaks out to the user. The exposed API wraps/unwraps both parts at once. I don't understand what EDIT: Fixed MonadError link. |
@Twisol I mean a type Basically if I have a monad / applicative / functor that contains For example function fmapEither(functor, lambda) {
return functor.map(function (box) {
return box.left ? box.left : lambda(box.right)
})
} This function works on all |
I still have the "colorless green ideas sleep furiously" problem with your syntax, but I see what you mean. Functors can be trivially composed, but monads cannot. One way to do this between specific pairs of monads is to use monad transformers. Unfortunately, that requires a bit more help from the type system to do generically than Javascript provides. As far as functors go, in Haskell one might trivially use
I reframed |
How about adding the MonadError type class? http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/Control-Monad-Error-Class.html |
I was reading through http://book.realworldhaskell.org/read/error-handling.html and trying to see how it would be adapted to Fantasy Land js, but struggling a little bit. I would really appreciate if anyone could come up with some example code to deal with this situation:
Assume some Fantasy Land compliant promises implementation:
The text was updated successfully, but these errors were encountered: