Haskell Fay sequential asynchronous calls
I recently decided to port some javascript code to Fay so that I can ensure that the font is correct and so that I can handle async in a neat way (and also experiment). I created several javascript objects whose sole purpose was to synchronize concurrent ajax calls. I am new to Haskell.
In Fay, I was hoping to strip away a few ajax calls and use, say, Control.Monad.Parallel.sequence to make them syncronized. However, I am stuck and desperate for a tutorial because fay-jquery AJAX functions do not return a monad for success / failure callbacks, and this example in fay snaplet does too. They all return the monad Fay (), which seems to be for ordering Hackell's lazy calls into strict javascript expressions together, whereas I was sort of expecting something like a tuple (Fay (), IO (or SuccessResult FailureResult)) since firing off the AJAX request results in two different actions.
I have many questions about this:
- Is the continuation of the monad what I'm looking for?
- Are there modules that work with Fay and use this monad for asynchronous javascript?
- Since the side effect of the fay-jquery AJAX function happens after everything is bound or ordered after the returned Fay (), does this make the function impure?
- I notice the continuation of the monad in the Fay repository - why isn't it used in Fay itself? The only thing I can find is this object that wraps the async node.js fs calls .
Replies will be much appreciated! They will be of immense help to my shaky understanding of this material.
source to share
- Yes. The Cont example practically does what you want with no error handling.
- ^
- It depends on your definition of "unclean". I would say that the function returned before all of its effects can be clean. This applies to almost all lazy evaluation in Haskell. see for example Haskell
forkIO :: IO () -> IO ThreadId
- I'm not sure what you mean by "in Fay itself". I don't think Prelude should use this, but other libraries can use Cont, and if you want that doesn't do the package from the example.
source to share