2013-07-14 67 views
1

我有一個腳手架的網站,我在Home Handler中使用這段代碼。maybeAuthId類型錯誤

{-# LANGUAGE TupleSections, OverloadedStrings #-} 
module Handler.Home where 

import Import 
import Yesod.Auth 

getHomeR :: Handler RepHtml 
getHomeR = do 
    defaultLayout $ do 
    maid <- maybeAuthId 
    setTitle "Welcome!" 
    $(widgetFile "homepage") 

我想訪問maid我homepage.hamlet文件。不過,我得到以下錯誤:

Handler/Home.hs:10:17: 
    Couldn't match expected type `WidgetT site0 IO t0' 
       with actual type `HandlerT master0 IO (Maybe (AuthId master0))' 
    In a stmt of a 'do' block: maid <- maybeAuthId 
    In the second argument of `($)', namely 
     `do { maid <- maybeAuthId; 
      setTitle "Welcome!"; 
      $(widgetFile "homepage") }' 
    In a stmt of a 'do' block: 
     defaultLayout 
     $ do { maid <- maybeAuthId; 
      setTitle "Welcome!"; 
      $(widgetFile "homepage") } 

我得到我是否往裏放homepage.hamlet任何內容,上面的錯誤消息。而不是使用$(widgetFile "homepage"),如果我粘貼Yesod Book(Auth部分)的whamlet代碼片段,它可以正常工作。

如果我刪除了對maybeAuthId的調用,問題也會消失。我猜這是與調用maybeAuthId和使用widgetFile有關,但我不知道如何解決這個問題。任何幫助讚賞。

謝謝!

回答

2

maybeAuthId生活在Handler單子,和defaultLayout內爲Widget,這就是爲什麼你有一個不匹配。你可以做下列之一:

  • 轉換的Handler行動使用handlerToWidget
  • 移動maybeAuthId調用之前defaultLayout
+0

謝謝你,邁克爾Widget行動。它的工作,並感謝解釋以及。 – Ecognium