title: Haskell / Persistent-Sqlite: "No instance for (Control.Monad.Trans.Resource.MonadResource IO)"
body: <p>I've been trying to come up with a simple and intuitive way to use databases with Haskell. I've taken this code from the <a href="http://www.yesodweb.com/book/persistent" rel="noreferrer">Yesod book</a> and tried to clean it up so that it can be easier to understand and use.</p>
  
  <pre><code>{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies, OverloadedStrings #-}
  {-# LANGUAGE GADTs, FlexibleContexts #-}
  
  import Database.Persist
  import Database.Persist.Sqlite (withSqliteConn, runSqlConn, runMigration)
  import Database.Persist.TH (share, mkPersist, mkMigrate, sqlSettings, persist)
  
  share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist|
  Person                              -- Table name
      name String                     -- String value
      age Int Maybe                   -- Numerical value
  |]
  
  updateDB x y = withSqliteConn "data.db" $ runSqlConn $ do
      runMigration migrateAll         -- Creates "Person" table if one doesn't exist
      insert $ Person x $ Just y      -- Inserts values into .db file
  
  main = do
      updateDB "Frank Silver" 40      -- adds name "Frank Silver" and age "40" to data.db file
  </code></pre>
  
  <p>This code <em>almost</em> works, but I get the following error which I haven't been able to resolve.</p>
  
  <pre><code>No instance for (Control.Monad.Trans.Resource.MonadResource IO)
        arising from a use of `updateDB'
      Possible fix:
        add an instance declaration for
        (Control.Monad.Trans.Resource.MonadResource IO)
      In a stmt of a 'do' block: updateDB "Frank Silver" 40
      In the expression: do { updateDB "Frank Silver" 40 }
      In an equation for `main': main = do { updateDB "Frank Silver" 40 }
  </code></pre>
  
  <p>Any suggestions pointing me in the right direction would be appreciated.</p>