Overlapping instances for HasAcidState error

26 views
Skip to first unread message

Pete Ryland

unread,
Oct 22, 2013, 9:52:33 AM10/22/13
to ha...@googlegroups.com
So I'm trying to update my app to use 0.5.1 version of happstack-foundation but I've come across the following error.

As I think is necessary, I've changed my type aliases to refer to (AcidState MyAppState) instead of MyAppState, like such:

type MyApp' = FoundationT' Route (AcidState MyAppState) () IO
type MyApp  = XMLGenT MyApp'

but I'm getting this:

src/MyApp/Web/Pages/Common.hs:71:27:
    Overlapping instances for HasAcidState
                                (XMLGenT
                                   (RouteT
                                      Route
                                      (StateT
                                         (Happstack.Foundation.AppState
                                            Route (AcidState MyApp.Model.MyAppState) ())
                                         (ServerPartT IO))))
                                MyApp.Model.MyAppState
      arising from a use of `query'
    Matching instances:
      instance (Functor m, Monad m) =>
               HasAcidState
                 (FoundationT url (AcidState acidState) requestState m) acidState
        -- Defined in `Happstack.Foundation'
      instance HasAcidState (FoundationT' url acid reqSt m) acidSt =>
               HasAcidState (XMLGenT (FoundationT' url acid reqSt m)) acidSt
        -- Defined in `Happstack.Foundation'
    In a stmt of a 'do' block: mUser <- query GetUser
    In the expression:
      do { here <- whereami;
           mUser <- query GetUser;
           (genElement
              (Nothing, fromStringLit "html")
              [asAttr (fromStringLit "lang" := MsgLang)]
              [asChild ((genElement (Nothing, fromStringLit "head") [] [...])),
               asChild ((genElement (Nothing, fromStringLit "body") [] [...]))]) }
    In an equation for `myAppHTML':
        myAppHTML
          = do { here <- whereami;
                 mUser <- query GetUser;
                 .... }
cabal: Error: some packages failed to install:
myapp-0.1.0.3 failed during the building phase. The exception was:
ExitFailure 1

Commenting out the new instance seems to fix it, but I can't really see why it's getting confused since this should be a different type.

pdr@home:code/happstack/happstack-foundation$ darcs diff
diff -rN -u old-happstack/happstack-foundation/Happstack/Foundation.hs new-happstack/happstack-foundation/Happstack/Foundation.hs
--- old-happstack/happstack-foundation/Happstack/Foundation.hs 2013-10-22 15:36:50.336812563 +0200
+++ new-happstack/happstack-foundation/Happstack/Foundation.hs 2013-10-22 15:36:51.740812586 +0200
@@ -99,8 +99,8 @@
     getAcidState :: m (AcidState st)
 
 
-instance (HasAcidState (FoundationT' url acid reqSt m) acidSt) => HasAcidState (XMLGenT (FoundationT' url acid reqSt m)) acidSt where
-    getAcidState = XMLGenT getAcidState
+-- instance (HasAcidState (FoundationT' url acid reqSt m) acidSt) => HasAcidState (XMLGenT (FoundationT' url acid reqSt m)) acidSt where
+--     getAcidState = XMLGenT getAcidState
 
 
 getAcidSt :: (Functor m, MonadState (AppState url acidState requestState) m) => m acidState

So that seems to work, but I'm also now getting thread hangs, probably from acid-state but I'll send a separate post about that since I'm still trying to fix it or at least isolate the cause.

By the way, I tried simply downgrading to foundation 0.4 again, but then acid-state 0.11.4 failed to compile with this error:

$ cabal install acid-state-0.11.4
Resolving dependencies...
Configuring acid-state-0.11.4...
Building acid-state-0.11.4...
Preprocessing library acid-state-0.11.4...
[ 1 of 15] Compiling Data.Acid.CRC    ( src/Data/Acid/CRC.hs, dist/build/Data/Acid/CRC.o )
[ 2 of 15] Compiling Paths_acid_state ( dist/build/autogen/Paths_acid_state.hs, dist/build/Paths_acid_state.o )
[ 3 of 15] Compiling Data.Acid.Archive ( src/Data/Acid/Archive.hs, dist/build/Data/Acid/Archive.o )

src/Data/Acid/Archive.hs:65:19:
    Constructor `Serialize.Fail' should have 2 arguments, but has been given 1
    In the pattern: Serialize.Fail msg
    In a case alternative: Serialize.Fail msg -> Fail msg
    In the expression:
      case result of {
        Serialize.Done entry rest
          | Strict.null rest -> Next entry (worker more)
          | otherwise -> Next entry (worker (rest : more))
        Serialize.Fail msg -> Fail msg
        Serialize.Partial cont
          -> case more of {
               [] -> check (cont Strict.empty) []
               (x : xs) -> check (cont x) xs } }
cabal: Error: some packages failed to install:
acid-state-0.11.4 failed during the building phase. The exception was:
ExitFailure 1

This is all from a fresh cabal, built using:

# remove ~/.cabal and ~/.ghc directories
cabal update
cabal install mtl bytestring directory
cabal install hsx2hs
cabal install regex-posix regex-compat regex-base --force-reinstalls
cabal install data-default time-compat nats transformers-base split primitive semigroups base-unicode-symbols lifted-base resourcet stm mmorph vector hscolour text ixset hlint certificate shakespeare-i18n shakespeare hslogger happstack-server happstack-foundation happstack-hsp happstack certificate tls-extra tls fast-logger monad-logger conduit zlib-conduit xml-conduit acid-state SHA pwstore-purehaskell

Cheers,
Pete

Pete Ryland

unread,
Jul 8, 2015, 4:06:38 PM7/8/15
to ha...@googlegroups.com
I know this post is old, but I've finally worked out what I needed to do to fix this issue.  See inline comments below.

On 22 October 2013 at 15:52, Pete Ryland <p...@pdr.cx> wrote:
So I'm trying to update my app to use 0.5.1 version of happstack-foundation but I've come across the following error.

As I think is necessary, I've changed my type aliases to refer to (AcidState MyAppState) instead of MyAppState, like such:

type MyApp' = FoundationT' Route (AcidState MyAppState) () IO
type MyApp  = XMLGenT MyApp'

So to avoid the overlapping instance, what I needed to do was to add in another type to encapsulate the AcidState and provide the instance, like CtrlV does:

data MyAppAcid = MyAppAcid { acidSt :: AcidState MyAppState }

type MyApp' = FoundationT' Route MyAppAcid () IO
type MyApp  = XMLGenT MyApp'

instance (Functor m, Monad m) => HasAcidState (FoundationT' u MyAppAcid r m) MyAppState where
  getAcidState = acidSt <$> getAcidSt

I hope that helps someone else with the same problem.

Cheers,
Pete
Reply all
Reply to author
Forward
0 new messages