我怀疑为什么会发生这种情况。我一直在关注“Yesod Web”电子书,但有一个脚手架网站。当我到达想要在“消息”文件中应用“复数”功能的位置时,编译器返回此错误:
Foundation.hs:52:1:不在范围内:“复数”
在与我称之为“小村庄”的文件相同的 hs 文件中声明复数的地方。但是,如果我将函数声明移到“Foundation.hs”文件中的第 52 行之前,那么错误就会消失,它让我可以有效地编译它。为什么会这样??
module Handler.UserProfile where
import Import
import Data.Maybe (fromMaybe)
import Data.Text (pack, unpack)
viewCountName :: Text
viewCountName = "UserProfileViews"
readInt :: String -> Int
readInt = read
plural :: Int -> String -> String -> String
plural 1 x _ = x
plural _ _ y = y
getUserProfileR :: Handler RepHtml
getUserProfileR = do
viewCount <- lookupSession viewCountName
>>= return . (1 +) . readInt . unpack . fromMaybe "0"
setSession viewCountName (pack $ show viewCount)
maid <- maybeAuth
--msg <- getMessageRender
let user = case maid of
Nothing -> "(Unknown User ID)" --show MsgHello --
Just (Entity _ u) -> userEmail u
defaultLayout $ do
setTitleI MsgUserProfile
$(widgetFile "nhUserProfile")