brendanhay/gogol

"Couldn't match type [...] ("https://www.googleapis.com/auth/datastore" Data.Type.Equality.== "https://www.googleapis.com/auth/datastore") [...] with ‘'True’"

Opened this issue · 5 comments

I have this function, which I use to make Datastore requests:

sendReq' :: ( DatastoreM m
            , HasScope '[AuthDatastore] a
            , GoogleRequest a)
         => (ProjectId -> a)
         -> m (Rs a)
sendReq' mkReq = do
    pid <- getPid
    liftGoogle $ Google.send (mkReq pid)

The DatastoreM monad just has a few things in a config, like the ProjectId. I use it like this:

runQueryReq :: DatastoreM m
         => Maybe TxId
         -> RunQueryRequest
         -> m RunQueryResponse
runQueryReq txM req =
    sendReq' (projectsRunQuery txReq)
  where
    txReq = maybe req (`atomically` req) txM

but I get the error below for the above function, and I can't figure out why. It happens for all projects, not just projectsRunQuery.

It's solved by adding HasScope '[AuthDatastore] <Project> to the constraint list for the function that needs to consume from sendReq' (eg. runQueryReq), but then I also need to add it to the next function, and so on, until I'm out in a class instance definition, and I need to use UndecidableInstances in order to enable it here.

Can you tell me why this happens, and if there's something I'm doing wrong, or if it's GHC acting up?

   /Users/rune/IdeaProjects/promissory-note-app/paychan-datastore/src/DB/Request/Query.hs:43:5: error:
        • Couldn't match type ‘(("https://www.googleapis.com/auth/datastore"
                                 Data.Type.Equality.== "https://www.googleapis.com/auth/cloud-platform")
                                Data.Type.Bool.|| ("https://www.googleapis.com/auth/datastore"
                                                   Data.Type.Equality.== "https://www.googleapis.com/auth/datastore"))
                               Data.Type.Bool.|| Network.Google.Auth.Scope.HasScope'
                                                   '[]
                                                   '["https://www.googleapis.com/auth/cloud-platform",
                                                     "https://www.googleapis.com/auth/datastore"]’
                         with ‘'True’
            arising from a use of ‘sendReq'’
        • In the expression: sendReq' (projectsRunQuery txReq)
          In an equation for ‘runQueryReq’:
              runQueryReq txM reqT
                = sendReq' (projectsRunQuery txReq)
                where
                    txReq = maybe req (`atomically` req) txM
                    req = unTagged reqT

Hi @runeksvendsen, I've seen your message but I haven't had time to dig in and provide a clear example. The short version is that class constraints will propagate all the way though the code as you've seen. constraints need to be discharged - and to do that possibly an additional combinator may need to be provided.

Allow me to shortly summarize what I don't understand, and what leads me to think there's a bug somewhere. The error I receive is:

    • Couldn't match type ‘(("https://www.googleapis.com/auth/datastore"
                             Data.Type.Equality.== "https://www.googleapis.com/auth/cloud-platform")
                            Data.Type.Bool.|| ("https://www.googleapis.com/auth/datastore"
                                               Data.Type.Equality.== "https://www.googleapis.com/auth/datastore"))
                           Data.Type.Bool.|| Network.Google.Auth.Scope.HasScope'
                                               '[]
                                               '["https://www.googleapis.com/auth/cloud-platform",
                                                 "https://www.googleapis.com/auth/datastore"]’
                     with ‘'True’

The second sub-expression in the expression that allegedly doesn't evaluate to 'True is ("https://www.googleapis.com/auth/datastore" Data.Type.Equality.== "https://www.googleapis.com/auth/datastore") which, as far as both GHCi and I can see, should evaluate to 'True.

Please enlighten me here.

This is a problem for me as well. Cleaning and rebuilding works, but that takes a long time so a workaround would be appreciated.

I am also experiencing this problem, quite consistently: touch a file that uses this, and it breaks. Clean and rebuild, and it works until you touch the file again.

It seems like it may be a GHC bug related to interface files and type families, but I'm not sure.

Add the following import to your file to fix this:

import GHC.TypeLits ()

It contains the following bit of code which declares the type instance that is required to compare symbols.

type family EqSymbol (a :: Symbol) (b :: Symbol) where
  EqSymbol a a = 'True
  EqSymbol a b = 'False
type instance a == b = EqSymbol a b