Haskell / Persistent-Sqlite: “No instance for (Control.Monad.Trans.Resource.MonadResource IO)”

前端 未结 1 1742
不思量自难忘°
不思量自难忘° 2021-01-17 18:30

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 Yesod book and tried to clean it up so that it can

相关标签:
1条回答
  • 2021-01-17 19:18

    With

    main = do
        updateDB "Frank Silver" 40
    

    the type of updateDB "Frank Silver" 40 is inferred to be IO (), since that's the default type for main (it must have type IO a for some a). But from the definition, its type is inferred to be MonadRescource m => m a for some a (probably a = (), but I'm not sure), and there is no instance MonadResource IO. So you need something to transform the updateDB to an IO action, the normal way to do that is runResourceT, which transforms a ResourceT m a into an m a (here m = IO), so

    main = runResourceT $ updateDB "Frank Silver" 40
    

    works.

    0 讨论(0)
提交回复
热议问题