Recently, I decided to port some javascript code to Fay, so that I could guarantee type correctness, and so that I could handle async in a neat way (and also to experiment). I had built a few javascript objects whose only purpose was to synchronise parallel ajax calls. I am quite new to Haskell.
In Fay, I was hoping to fire off a few ajax calls, and use, say, Control.Monad.Parallel.sequence to make them synchronize. However, I'm stuck and in desperate need of guidance because the fay-jquery AJAX functions don't return a monad for the success/failure callbacks, and this example in the fay snaplet doesn't either. They all return a Fay () monad which just appears to be for sequencing lazy haskell calls into strict javascript statements together, whereas I was kind of expecting something like a tuple of (Fay (), IO (Either SuccessResult FailureResult)), since firing off an AJAX request results in two different actions.
I have lots of questions about this:
- Is the continuation monad what I'm looking for?
- Are there any modules that work with Fay, and use this monad for asynchronous javascript?
- Since the side effect of fay-jquery's AJAX functions occurs after anything bound or sequenced after the returned Fay (), does this make the functions impure?
- I notice a continuation monad in the Fay repo - Why isn't it used in Fay itself? The only thing I can find is this gist which wraps async node.js fs calls.
Answers would be much appreciated! They would massively help my shaky understanding of this stuff.