Skip to content

pkamenarsky/haskell-ajax-cont

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Asynchronous http requests using the continuation monad

An asynchronous ajax request function would look like this:

ajax :: String -> (String -> IO ()) -> IO ()

This looks exactly like the type of the continuation monad: (a -> r) -> r. Rewriting ajax for ContT yields:

ajax :: String -> ContT () IO String

Now, we can use ajax in a monadic computation:

f = do
    a <- ajax "http://bla.com"
    b <- ajax "http://example.com"
    return $ a ++ b

Note that we write code sequentially although ajax is asynchronous!

About

Asynchronous http requests using the continuation monad

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published