WebCont-0.0.1: Continuation based web programming for Happstack



WebConts allow simple continuation based behavior in Happstack applications through the use of cookies and an IntMap on the server mapping cookie names to continuations. It is based on the paste http://gist.github.com/260052. For the arc challenge:

    arc = do
        name <- doform' frm
        display $ samelink "click here"
        display $ "you said" ++ name

A more complicated example, creating a User datatype with a different page for each field:

   data User = User {age:: Int, name::String, dead::Bool} deriving (Show)
   makeUser = liftM3 User age name dead >>= (display . show) where
       age = doform' $ label "Age: " *> frm
       name = doform' $ label "Name: " *> frm
       dead = doform' $ label "Dead?: " *> frm

To run the continuations in Happstack, use runStateless or runWithState, giving each continuation in a list as a parameter, depending on whether you want MACID support enabled:

   runStateless nullConf [arc, makeUser] []



doform :: (Html -> r) -> ([String] -> Html -> r) -> ContForm a -> WebCont r aSource

Lift a form into the WebCont monad using a function

doform' :: ContForm a -> WebCont Html aSource

Lift a form into the WebCont monad without embellishment, displaying errors inline

runWithState :: (Methods a, Component a) => Conf -> Proxy a -> [WebCont Html ()] -> [ServerPartT IO Response] -> IO ()Source

Entry point for the continuation server: sets up continuation table, MACID state, and a chron job to add a checkpoint daily

runStateless :: Conf -> [WebCont Html ()] -> [ServerPartT IO Response] -> IO ()Source

Entry point for the continuation server: starts the server without MACID support

display :: HTML a => a -> WebCont Html ()Source

Display a page, ignoring the value

samelink :: HTML a => a -> HotLinkSource

Links to the same page, leading to the next step in a continuation

button :: String -> a -> WebCont Html aSource

Button with an associated value

link :: HTML l => l -> a -> WebCont Html aSource

Link with an associated value

newtype WebCont r a Source

A WebCont is a function from Env to a value of a, displaying a response of r. Both r and a must be Html for runnable continuations.




runWeb :: Env -> Result r a


Monad (WebCont r) 
Show (WebCont r a) 
(Monoid r, Monoid a) => Monoid (WebCont r a) 
Monoid a => Monoid (WebCont a a) 

data Result r a Source


Done a 
Via r (WebCont r a) 


(Show r, Show a) => Show (Result r a) 

class DefaultForm i whereSource

Defines a normal form style to use for a given type

nullConf :: Conf

Default configuration contains no validator and the port is set to 8000