4
我试图使用持久与Yesod从我的数据库中的表中获取所有字段键的列表。我的访问代码如下:“类型变量不明确”与Haskell中的持久Yesod
getMapList :: Handler [Text]
getMapList = runDB $ do
dbList <- selectList [] []
return (map getMapName dbList)
where getMapName (Entity (Key (PersistText mapName)) _) = mapName
请注意,这是一个游戏:“地图”在这里是游戏意义上的地图,而不是在哈斯克尔感。
我得到以下错误,它表明类型推理引擎根据我使用的数据库后端无法计算出我的类型。
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
我试着用GameMapGeneric代替KingsLadiesInWaitingGenerc,我得到以下错误:不在范围内:类型构造函数或类“GameMapGeneric”。有什么特别的我需要导入?我正在使用一个脚手架站点,所以我已经把这个分散在一堆文件上,我的处理程序都在他们自己的文件中。 – jmite
当您运行“yesod init”时,它应该创建一个名为Model.hs的文件,您需要使用该函数在文件中导入该文件。实际模型应该在config/models中,因此您还可以验证表“GameMap”存在。 – jamshidh
我仍然得到错误,当我做“导入模型(GameMapGeneric)”我得到“模块'模型'不导出'GameMapGeneric'”。有什么想法吗?非常感谢迄今为止所有的帮助。 – jmite