在我的Yesod网络应用程序中,我有以下数据类型,在我的模型中使用类似Enum:
data ImageType = U | P | G
deriving (Show, Read, Enum, Eq, Bounded)
derivePersistField "ImageType"
我希望在我的路线上使用ImageType
作为参数
/plain/#ImageType PlainR GET
所以我将ImageType
实例设为PathPiece
imageTypeToText :: ImageType -> T.Text
imageTypeToText U = "U"
imageTypeToText P = "P"
imageTypeToText G = "G"
instance PathPiece ImageType where
toPathPiece = imageTypeToText
fromPathPiece s = case (s == "U") of
False -> Nothing
True -> Just $ U
问题是得到以下错误
Foundation.hs:97:15: 无法匹配类型'ImageType - >路线应用' 使用'Route(HandlerSite(WidgetT App IO))' 预期类型:WidgetT App IO((ImageType - > Route App) - > [(Text,Text)] - > Text) 实际类型:WidgetT 应用 IO (路由(HandlerSite(WidgetT App IO)) - > [(文本,文本)] - >文本) 在'(>> =)'的第一个参数中,即'getUrlRenderParams' 在'do'块的stmt中: (getUrlRenderParams
= (\ urender_a1tOQ - > (asWidgetT GHC.Base .. toWidget) (toHtml(\ u_a1tOR - > urender_a1tOQ u_a1tOR [] PlainR))))
Foundation.hs代码是
$(widgetFile "default-layout") --Line 97
withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")