Yesst와 함께 Persistent를 사용하여 데이터베이스의 테이블에서 모든 필드 키 목록을 가져 오려고합니다. 다음과 같이 내 접근 코드는 다음과 같습니다 여기되지 하스켈 의미에서, 게임 감각의지도입니다 "지도":이 게임이다"타입 변수가 모호합니다"예 : Hastock에서 지속됨 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
KingsLadiesInWaitingGenerc 대신 GameMapGeneric을 사용해 보았습니다. 다음과 같은 오류가 나타납니다. 범위 내에 있지 않습니다 : 형식 생성자 또는 클래스'GameMapGeneric '. 특히 가져올 필요가있는 것이 있습니까? 저는 스캐 폴딩 된 사이트를 사용하고 있습니다. 그래서이 파일들을 여러개의 파일에 분산 시켰고, 핸들러는 각각 자신의 파일에 있습니다. – jmite
"yesod init"을 실행하면 Model.hs라는 파일이 만들어 져야합니다.이 파일은 함수와 함께 파일로 가져와야합니다. 실제 모델은 config/models에 있어야하므로 "GameMap"테이블이 있는지 확인할 수도 있습니다. – jamshidh
여전히 오류가 발생하고 "가져 오기 모델 (GameMapGeneric)"을 수행 할 때 "모듈 '모델'이 (가) 'GameMapGeneric'을 (를) 내 보내지 않습니다. 이견있는 사람? 지금까지 모든 도움에 감사드립니다. – jmite