我对 Haskell 很陌生,所以我无法吸收 Yesod 中使用的所有高级特性,例如类型实例和相等约束。我正在尝试在 Yesod 的测试框架中实现括号模式,以获得 setUp/tearDown 功能。这是我到目前为止所得到的(通过编辑更新):
module FishMother where
import Control.Exception.Lifted
import TestImport
import Database.Persist
import Database.Persist.GenericSql
import Model
insertYellowfinTuna :: OneSpec Connection FishId
insertYellowfinTuna = runDB . insert $ Fish "Yellowfin Tuna"
deleteFish :: FishId -> OneSpec Connection ()
deleteFish = runDB . delete
withYellowfinTuna :: FishId -> OneSpec Connection ()
withYellowfinTuna = bracket insertYellowfinTuna deleteFish
编译错误如下:
tests/FishMother.hs:18:21:
Couldn't match type `FishId
-> Control.Monad.Trans.State.Lazy.StateT
(Yesod.Test.OneSpecData Connection) IO ()'
with `Key SqlPersist Fish'
Expected type: FishId -> OneSpec Connection ()
Actual type: (FishId
-> Control.Monad.Trans.State.Lazy.StateT
(Yesod.Test.OneSpecData Connection) IO ())
-> Control.Monad.Trans.State.Lazy.StateT
(Yesod.Test.OneSpecData Connection) IO ()
In the return type of a call of `bracket'
In the expression: bracket insertYellowfinTuna deleteFish
In an equation for `withYellowfinTuna':
withYellowfinTuna = bracket insertYellowfinTuna deleteFish
我究竟做错了什么?