nurpax / snaplet-sqlite-simple

sqlite-simple snaplet for the Snap Framework
Other
8 stars 5 forks source link

Build Error: Could not deduce (StateType (Handler b Sqlite) ~ Sqlite) #14

Closed wochinge closed 9 years ago

wochinge commented 9 years ago

Hi there,

I am trying the new version 0.4.8.3 and I'm getting an error while I am building my project. The error is located for the HasSqlite instance. I added the import "Control.Monad.State" as it is shown in the example project, but cabal throws the error

"Could not deduce (StateType (Handler b Sqlite) ~ Sqlite) from the context (MonadCatchIO-transformers-0.3.1.3:Control.Monad.CatchIO.MonadCatchIO 
(Handler b App) bound by the instance declaration at libarary\Application.hs:22:5--24.
Expected type: Handler b Sqlite Sqlite
Actual type: Handler b Sqlite (StateType (Handler b Sqlite))
Relevant bindings include
 getSqliteState :: Handler b App Sqlite
  (bound at library\Application.hs:23:5)
In the second argument of `with', namely get'

My code is the following:

{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell   #-}
{-# LANGUAGE FlexibleInstances #-}

-- | Module, which defines and holds several sub snaplets.
module Application where

import           Control.Lens
import           Control.Monad.State
import           Snap
import           Snap.Snaplet
import           Snap.Snaplet.SqliteSimple

-- | Holds the snaplets.
data App = App { _playerDAO :: Snaplet Sqlite  }

-- | Creates the snaplet.
makeLenses ''App

-- | Provides a HasSqlite instance for this module.
instance HasSqlite (Handler b App) where
    getSqliteState = with playerDAO get

Cabal-version: 1.18.05 using 1.18.1.3 of Cabal library GHC: 7.8.3

nurpax commented 9 years ago

Thanks for the report. Is this a regression from the new snaplet-sqlite-simple-0.4.8.3 version, ie. was it working before?

The snaplet-sqlite-simple example app was building fine on GHC 7.6.3 on Travis: https://travis-ci.org/nurpax/snaplet-sqlite-simple/builds/66760603.

Did you try building in a clean sandbox? Have you recently updated with "cabal update"?

I suppose either the snaplet code doesn't (anymore) build on GHC 7.8 or later, or you have some different versions of some dependent libraries. Do you see any notable library version differences if you compare your locally installed versions against the ones picked up in https://travis-ci.org/nurpax/snaplet-sqlite-simple/builds/66760603?

Are you able to reproduce this in an isolated gist? Would be easier for me to take a look.

wochinge commented 9 years ago

Hi,

It worked before I updated to 0.4.8.3 aside from some strange random server time outs. But that's a different topic :) I used a clean sandbox and I updated cabel in order to get snaplet-sqlite-simple 0.4.8.3. My dependencies are a bit different. So I am using the latest snap (0.14.0.5), but I have to use snap core 0.9.6.3 instead of 0.9.7.0 because of this issue: https://github.com/snapframework/snap-core/issues/228. Also I am using the newer version 0.4.9.0 of sqlite-simple (instead of 0.4.8.0).

Edit: I am also using MonadCatchIO-transformers-0.3.1.3.

I tried to create a small gist of my problem: https://gist.github.com/wochinge/f84dc4f8fa8672827443

Thanks for your help!

error

nurpax commented 9 years ago

Hi @wochinge, I think the problem is in your use of monads-tf package for monad transformers. If I switch that package to mtl, your gist builds fine.

diff --git a/test.cabal b/test.cabal
index 7dea39a..990ca63 100644
--- a/test.cabal
+++ b/test.cabal
@@ -25,7 +25,7 @@ library
     exposed-modules:        Application
     build-depends:    
         base,
-        monads-tf,
+        mtl,
         snap == 0.14.0.5,
         blaze-builder,
         snap-core == 0.9.6.3, 

I've never actually come across monads-tf whereas mtl seems to be pretty common. The mtl package is one of the dependencies for snap so it seems like it's a pretty safe bet to use the same in apps too.

I have no idea why this build problem arose in the context of my snaplet-sqlite-simple update though. :)

wochinge commented 9 years ago

Thank you very much! It works now! Then nothing stops me from upgrading :-) I guess I added the dependeny a bit too fast when cabal complained ;)