Search code examples
haskelltypespersistentyesod

Could someone explain to me how I should go about fixing this type signature?


Here's the code, I tried letting type inference figure out the function's type. While the code compiles, it fails at runtime.

Ambiguous type variables `b0', `m0' in the constraint:
  (PersistBackend b0 m0) arising from a use of `isFree'
Probable fix: add a type signature that fixes these type variable(s)
In the expression: isFree testDay
In an equation for `it': it = isFree testDay

:t isFree

isFree :: PersistBackend b m => C.Day -> b m Bool

>isFree day = do
   match <- selectList [TestStartDate ==. day,
                        TestStatus !=. Passed,
                        TestStatus !=. Failed] []
   if (L.null match) then (liftIO $ return True) else (liftIO $ return False)

Solution

  • This is embarrassing. One one hand, this problem did get me to delve into the depths of Yesod monads. One the other hand, this question was already answered for me. When you run a database action, pass the result to runDB like so.

    >isFree day = do
       match <- runDB $ selectList [TestStartDate ==. day,
                                    TestStatus !=. Passed,
                                    TestStatus !=. Failed] []
       if (L.null match) then (liftIO $ return True) else (liftIO $ return False)