Note that there are some explanatory texts on larger screens.

plurals
  1. POYesod/Persistent testing with bracket pattern
    primarykey
    data
    text
    <p>I'm very new to Haskell, so I'm having trouble absorbing all of the advanced features used in Yesod such as <a href="http://www.haskell.org/haskellwiki/GHC/Type_families#Instance_declarations_2" rel="nofollow">type instances</a> and <a href="http://www.haskell.org/haskellwiki/Type_families#Equality_constraints" rel="nofollow">equality constraints</a>. I am trying to implement the <a href="http://www.haskell.org/haskellwiki/Bracket_pattern" rel="nofollow">bracket pattern</a> in Yesod's test framework in order to get setUp/tearDown functionality. Here's what I've got so far (updated via edit):</p> <pre><code>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 -&gt; OneSpec Connection () deleteFish = runDB . delete withYellowfinTuna :: FishId -&gt; OneSpec Connection () withYellowfinTuna = bracket insertYellowfinTuna deleteFish </code></pre> <p>The compile errors are as follows:</p> <pre><code>tests/FishMother.hs:18:21: Couldn't match type `FishId -&gt; Control.Monad.Trans.State.Lazy.StateT (Yesod.Test.OneSpecData Connection) IO ()' with `Key SqlPersist Fish' Expected type: FishId -&gt; OneSpec Connection () Actual type: (FishId -&gt; Control.Monad.Trans.State.Lazy.StateT (Yesod.Test.OneSpecData Connection) IO ()) -&gt; 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 </code></pre> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload