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 a
- doform' :: ContForm a -> WebCont Html a
- runWithState :: (Methods a, Component a) => Conf -> Proxy a -> [WebCont Html ()] -> [ServerPartT IO Response] -> IO ()
- runStateless :: Conf -> [WebCont Html ()] -> [ServerPartT IO Response] -> IO ()
- display :: HTML a => a -> WebCont Html ()
- samelink :: HTML a => a -> HotLink
- button :: String -> a -> WebCont Html a
- link :: HTML l => l -> a -> WebCont Html a
- newtype WebCont r a = WebCont {}
- data Result r a
- type ContForm a = XHtmlForm Identity a
- class DefaultForm i where
- nullConf :: Conf
Documentation
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
samelink :: HTML a => a -> HotLinkSource
Links to the same page, leading to the next step in a continuation
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.
class DefaultForm i whereSource
Defines a normal form style to use for a given type
DefaultForm Bool | |
DefaultForm Int | |
DefaultForm Integer | |
DefaultForm String | |
(DefaultForm a, DefaultForm b) => DefaultForm (a, b) |