无法在 Yesod 中找到与导入相关的类型 Import.hs
Unable to find type relating to import in Yesod Import.hs
我输入了Import.hs
import qualified Database.Esqueleto as E
但是在我的处理程序文件中我有
import Import
但是找不到E
module Handler.MyProfile where
import Import
getMyProfileR :: Handler Html
getMyProfileR = do
now <- liftIO getCurrentTime
wordList <- (runDB $ E.select $ E.from $ \v -> do
where_ (v ^. VocabularyDate E.<. val now)
return v)
defaultLayout $ do
$(widgetFile "myprofile")
这不可能。它会破坏合格进口的主要目的:qualifier-prefix 告诉您某些东西来自哪里。如果您的代码中有 E.<.
,reader 希望能够看到它的来源!
您有两个选择:
- 直接把
import qualified Database.Esqueleto as E
放在Handler.MyProfile
中。这通常是最好的解决方案——虽然它会导致每个源文件顶部的 headers 有点笨拙,但优点是人们可以立即看到所有内容的来源。是的,它违反了 DRY,但我认为在这种情况下它仍然是合理的。
为 esqueleto 制作一个专用的“导入模块”。并且,如有必要,对于您拥有的任何其他 import-qualifier 前缀。
module Import.Esqueleto where -- package-local, hidden module
import Database.Esqueleto
import Database.Esqueleto....
module Handler.MyProfile where
import qualified Import.Esqueleto as E
我输入了Import.hs
import qualified Database.Esqueleto as E
但是在我的处理程序文件中我有
import Import
但是找不到E
module Handler.MyProfile where
import Import
getMyProfileR :: Handler Html
getMyProfileR = do
now <- liftIO getCurrentTime
wordList <- (runDB $ E.select $ E.from $ \v -> do
where_ (v ^. VocabularyDate E.<. val now)
return v)
defaultLayout $ do
$(widgetFile "myprofile")
这不可能。它会破坏合格进口的主要目的:qualifier-prefix 告诉您某些东西来自哪里。如果您的代码中有 E.<.
,reader 希望能够看到它的来源!
您有两个选择:
- 直接把
import qualified Database.Esqueleto as E
放在Handler.MyProfile
中。这通常是最好的解决方案——虽然它会导致每个源文件顶部的 headers 有点笨拙,但优点是人们可以立即看到所有内容的来源。是的,它违反了 DRY,但我认为在这种情况下它仍然是合理的。 为 esqueleto 制作一个专用的“导入模块”。并且,如有必要,对于您拥有的任何其他 import-qualifier 前缀。
module Import.Esqueleto where -- package-local, hidden module import Database.Esqueleto import Database.Esqueleto.... module Handler.MyProfile where import qualified Import.Esqueleto as E