3

I'm looking to port JS code which runs two AJAX calls in parrallel but needs both to complete before operating. With JQuery you can do:

$.when($.getJSON('/configVal'),
    $.getJSON('/configdesc'))
    .then(function(configByPluginResponse, configSpecResponse) {

Now I'm not sure how to handle with with Fay. The multithread parts of haskell are not available. I don't really want a state monad, because I want both fetches to run in parrallel, not sequentially.

I've spotted in the Fay source this example, Cont.hs. I'm not sure it can actually solve the problem, but anyway it doesn't compile if I just run "fay Cont.hs"; it complains about not knowing GHC.Base.Monad. This is with the current GIT head of Fay.

EDIT: I would like if possible pleasing Haskell semantics, if not... then yes, wrapping jquery's "then". I'm not sure how to achieve continuations or FRP with Fay, guidance with that would be appreciated (for FRP it's questionable wether Fay is expressive enough). So as a second choice I would just wrap the "then" but if possible I would really like it to accept any number of concurrent ajax requests, as the JS does (probably through an array), which may be complicated to achieve. I'll give it a shot myself, but I think I won't make it.

I saw in the fay-jquery bindings this comment:

-- TODO: jQuery['when'](): figure out Deferred first

I did manage to compile Cont.hs, I had to use the --no-ghc flag. So I'll check a bit, although the flag disables typecheck, not crazy about that.

It is frustrating to have to rely on JS libraries for such operations when I'm convinced that as a language Haskell is better equipped to solve such problems.

EDIT2: so it seems what I want are coroutines. I've seen some Haste code doing related things, but not doing exactly this. I would also accept a Haste or GHCJS solution to this problem.

EDIT3: Well in normall Haskell it seems this does it; I guess it would work with GHCJS and Haste, but in Fay it'll probably have to be wrapping of JS I guess...

Community
  • 1
  • 1
Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81
  • Are you looking for some pleasing Haskell semantics for parallel ajax calls? Then you might want to look into Continuations and FRP etc. If not, then simply using the Fay FFI to wrap the "then" method should do the trick. – Anupam Jain Aug 03 '13 at 06:21

0 Answers0