尝试将HSP和酸状态以Happstack的形式组合在一起

时间:2013-03-05 20:17:38

标签: haskell happstack acid-state

我跟着Happstack Crash Course,现在我想把不同的东西放在一起:

来自“使用改革的类型安全表单处理”(http://happstack.com/docs/crashcourse/Reform.html#reform)我已将此注册表格编码:

register :: AcidState UserBase -> ServerPart Response
register acid = unXMLGenT $
  appTemplate "register" () $
        reform (form "/register") "register" (insertAndRenderUser acid) Nothing registerForm

insertAndRenderUser :: (Monad m) => AcidState UserBase -> User -> AppT m XML
insertAndRenderUser acid user = 
    <dl>
      <dt>lastname:</dt>    <dd><% lastName user    %></dd>
      <dt>firstname:</dt>   <dd><% firstName user   %></dd>
      <dt>email:</dt> <dd><% email user %></dd>
      <dt>birthday:</dt> <dd><% show (birthday user) %></dd>
    </dl>


registerForm :: SimpleForm User
registerForm =
    User (UserId 0)
     <$> (errorList ++> label "Last name:"  ++>  (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "First name:" ++> (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "E-mail:"     ++> (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "Birthday:"   ++> (inputText "" `transformEither` requireDate) <++ br)
     <*  inputSubmit "Register"

现在我想在表单成功时添加注册用户。 我在酸状态(http://happstack.com/docs/crashcourse/AcidState.html#ixset

的帮助下对此UserBase进行了编码
insertUser :: MonadIO m => AcidState (EventState InsertUserIntern) -> User -> m (EventResult InsertUserIntern)  
insertUser acid user = do
  update' acid (InsertUserIntern user)

这些代码段是单独工作的,但我可以在insertUser acid user中插入insertAndRenderUser的哪个位置?

我希望你能帮助我 由于
FLO

1 个答案:

答案 0 :(得分:1)

自己弄明白

insertAndRenderUser acid user = do
  insertUser acid user 
  appTemplate "Your Registration" () $
    <dl>
      <dt>lastname:</dt>    <dd><% lastName user    %></dd>
      <dt>firstname:</dt>   <dd><% firstName user   %></dd>
      <dt>email:</dt> <dd><% email user %></dd>
      <dt>birthday:</dt> <dd><% show (birthday user) %></dd>
    </dl>