2017-09-14 35 views
1

我有呈现一个HTML标签,像这样一个简单的耶索德处理程序:路线插值失败,并在耶索德处理程序类型错误

getHomeR :: Yesod site => HandlerT site IO Html 
getHomeR = defaultLayout 
    [whamlet|$newline never 
<h1>Hello! 
|] 

我想打印的路线,并改变使用@{HomeR}代码路线插值语法,就像这样:

getHomeR :: Yesod site => HandlerT site IO Html 
getHomeR = defaultLayout 
    [whamlet|$newline never 
<h1>@{HomeR} 
|] 

插值在我耶索德处理器路线失败,此错误:

• Couldn't match type ‘site’ with ‘App’ 
    ‘site’ is a rigid type variable bound by 
    the type signature for: 
     getHomeR :: forall site. Yesod site => HandlerT site IO Html 
    at Handler/Home.hs:12:13 
    Expected type: WidgetT 
        site IO (Route App -> [(Text, Text)] -> Text) 
    Actual type: WidgetT 
        site 
        IO 
        (Route (HandlerSite (WidgetT site IO)) -> [(Text, Text)] -> Text) 

回答

1

Yesod site => HandlerT site IO Html类型允许的网站是任何耶索德实例然而,处理函数将只在它被用于创建的网站工作。

在这种情况下,您的Yesod实例被称为App(我相信这是脚手架网站的默认设置)。因此,正确的类型是: HandlerT App IO Html

假设你正在使用的脚手架网站(由于你的答案提Handler)然后耶索德创建类型同义词Handler意味着HandlerT App IO,这样你就不必继续键入它。

这就是为什么,因为你发现,Handler Html作品和你的原始版本没有。

1

更改类型签名getHomeR :: Handler Html