【发布时间】:2013-12-11 06:31:38
【问题描述】:
我正在尝试将 Persistent 与 Yesod 一起使用,以从我的数据库中的表中获取所有字段键的列表。我的访问器代码如下:
getMapList :: Handler [Text]
getMapList = runDB $ do
dbList <- selectList [] []
return (map getMapName dbList)
where getMapName (Entity (Key (PersistText mapName)) _) = mapName
注意这是一个游戏:这里的“地图”是游戏意义上的地图,而不是 Haskell 意义上的地图。
我收到以下错误,这表明类型推断引擎无法根据我使用的数据库后端确定我的类型。
Handler/Create.hs:101:13:
Couldn't match type `PersistEntityBackend t0'
with `persistent-1.2.3.0:Database.Persist.Sql.Types.SqlBackend'
The type variable `t0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Expected type: PersistMonadBackend (SqlPersistT (HandlerT App IO))
Actual type: PersistEntityBackend t0
In a stmt of a 'do' block: dbList <- selectList [] []
In the second argument of `($)', namely
`do { dbList <- selectList [] [];
return (map getMapName dbList) }'
In the expression:
runDB
$ do { dbList <- selectList [] [];
return (map getMapName dbList) }
有人知道如何解决这个问题吗?我需要在类型签名中添加什么才能正确地进行类型检查?谢谢!
编辑:我的模型是这样定义的:
GameMap
mapName Text
mapCode Text
UniqueGameMap mapName
deriving Typeable
【问题讨论】:
标签: haskell type-inference yesod persistent typechecking