それを行う1つの方法は(以下の説明)です:
getHomeR :: Handler Html
getHomeR = do
muid <- maybeAuthId
m <- case muid of
Nothing -> return Nothing
Just i -> runDB $ get i
defaultLayout $ do
[whamlet|
<p>Welcome!
$maybe user <- m
<p>
Welcome #{userIdent user}<br>
<a href=@{AuthR LogoutR}>Logout
$nothing
<p>
<a href=@{AuthR LoginR}>Go to the login page
|]
このようにして、Mayce Mays user out of m of mを作成し、テンプレートファイルでそれを解析します。に注意してください $maybe user <- m
, 、これは(大まかに)翻訳されます
case m of
Just user -> do
-- Do stuff with user, which is now of type User (and not Maybe User)
Nothing -> do
--Do stuff if m was nothing
だからあなたのワイルドカードをしない方が良いです $maybe _ <- muid