[web-devel] [Persistent] PersistBackend and the ErrorT monad

Max Cantor mxcantor at gmail.com
Wed Aug 24 11:33:43 CEST 2011


Hi,

I am trying to use an ErrorT monad inside some Persist code. 

I wrote the following instance:

newtype OcrError = OE String
...
instance PersistBackend m => PersistBackend (ErrorT OcrError m) where
  replace      k v = lift $ replace     k v
  update       k l = lift $ update      k l
  updateWhere  f u = lift $ updateWhere f u
  delete       = lift . delete      
  insert       = lift . insert 
  deleteBy     = lift . deleteBy    
  deleteWhere  = lift . deleteWhere 
  get          = lift . get         
  getBy        = lift . getBy       
  count        = lift . count       
  selectKeys f = selectKeys f
  selectEnum f o lim off = selectEnum f o lim off

It seems like there is a problem with selectEnum though.

In GHCI, this:

l :: [PersistKV OcrRefMap] <- rs $ selectEnum [] [] 0 0 

works fine, while this:

l :: Either OcrError [PersistKV OcrRefMap] <- rs $ runErrorT $ selectEnum [] [] 0 0 

hangs.  rs is a small function to run persist calls:
  rs :: (MonadControlIO m) => SqlPersist m a -> m a
  rs f = do
    let conn = DT.pack "user=hachicode password=password host=localhost port=5432 dbname=hachicode"
    withPostgresqlConn conn $ runSqlConn f

and you need -XScopedTypeVariables for the ghci commands.

Any advice? 

Thanks,
Max


More information about the web-devel mailing list