小编Axe*_*kel的帖子

带有IO String的setTitle会导致类型错误

我正在尝试将网页的标题设置为包含当前年份的字符串,如下所示:

getCurrentYear :: IO String
getCurrentYear = do
    now <- getCurrentTime
    let today = utctDay now
    let (year, _, _) = toGregorian today
    return $ show year

title :: IO Html
title = do
    y <- getCurrentYear
    return $ toHtml $ "Registration " ++ y

getRootR :: Handler RepHtml
getRootR = do
    (widget, enctype) <- generateFormPost personForm -- not important for the problem at hand, comes from the example in the yesod book
    defaultLayout $ do
        setTitle title -- this …
Run Code Online (Sandbox Code Playgroud)

haskell types yesod

1
推荐指数
1
解决办法
169
查看次数

标签 统计

haskell ×1

types ×1

yesod ×1