2015-05-02 58 views
1

這是O reilly - Yesod - Widgets的代碼片段,哈姆雷特庫缺少進口

getRootR = defaultLayout $ do 
    setTitle "My Page Title" 
    toWidget [lucius| h1 { color: green; } |] 
    addScriptRemote "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" 
    toWidget [julius| 
     $(function() { 
     $("h1").click(function(){ alert("You clicked on the heading!"); }); 
     }); 
    |] 
    toWidgetHead [hamlet| <meta name=keywords content="some sample keywords">|] 
    toWidget [hamlet| <h1>Here's one way of including content |] 
    [whamlet| <h2>Here's another |] 
    toWidgetBody [julius| alert("This is included in the body itself"); |] 

這段代碼產生的錯誤,

widget.hs:3:12: Not in scope: ‘defaultLayout’ 
widget.hs:4:3: Not in scope: ‘setTitle’ 
widget.hs:5:3: Not in scope: ‘toWidget’ 

什麼是從Hamlet的模塊,我需要進口,使這個工作? haskell是否具有自動完成功能,它會嘗試搜索和自動導入模塊名稱?

+1

您是否導入了'Yesod.Core'和'Yesod.Core.Widget'?解決了「未定義」錯誤的 – Sibi

+0

。謝謝你,西比 –

回答

2

導入Yesod.CoreYesod.Core.Widget,它們將提供適當的功能。

另請注意,他們有本書的online version。一般來說,如果您看到導入錯誤,請在Hoogle上進行搜索,並在大多數情況下您可能會在那裏找到解決方案。