2

私は永続的および永続的なmysqlを使用しています。私はMonad SqlMを持っています

type SqlM a = SqlPersist (ResourceT IO) a) 

私の機能の中で

testFun :: T.Text -> SqlM ()
testFun someId = ...

を使用してデータベースにクエリを実行できます

entity <- selectFirst [SomeField ==. someId]

しかし、エンティティを ID で選択したいと思います。someId を Key - Type に変換/パックする必要があります。私はこれがそれを行う方法ではないことを知っていますが、私は試しました:

entity <- get $ Key { unKey = PersistInt64 (read $ T.unpack someId) }

これは失敗します:

Couldn't match type `PersistEntityBackend
                       (Entity (DBTableGeneric backend0))'
              with `Database.Persist.GenericSql.Raw.SqlBackend'
The type variable `backend0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Expected type: Key (Entity (DBTableGeneric backend0))
  Actual type: KeyBackend
                 Database.Persist.GenericSql.Raw.SqlBackend
                 (Entity (DBTableGeneric backend0))
In the second argument of `($)', namely
  `Key {unKey = PersistInt64 (read $ T.unpack someId)}'

何がうまくいかないのですか?

4

1 に答える 1

4

私は通常、この種の変換にfromPathPieceを使用します。エラーメッセージについては、おそらく型シグネチャを追加して、使用している型をコンパイラに明確にすることができます。

于 2013-03-11T03:07:12.360 に答える