"No instance for" error - but instance exists (types do not match)

I get the following error from ghc for my servant library:

No instance for (GetEndpoint (Verb 'GET 200 '[JSON] Position) (Verb 'GET 200 '[JSON] Position) 'True) arising from a use of `callServer3' 

but I have an instance in scope that looks like this:

 instance GetEndpoint (Verb ns ct a) (Verb ns ct a) 'True where getEndpoint _ _ _ _ server = server 

which looks exactly like the one that ghc cannot find. I'm a little confused right now.

The full code can be found here:

Any clues? Thanks so much for any tips!

+5
source share
1 answer

This instance has a default type of '*' for ns ct and a. Or use poly views for both n and specific concrete views:

 (Verb (n :: k1) (s :: Nat) (ct :: [*]) a) 

The correct instance will look like this:

 instance GetEndpoint (Verb (n :: k1) (s :: Nat) (ct :: [*]) a) (Verb ns ct a) 'True where getEndpoint _ _ _ _ server = server 

If you don't want to include PolyKinds (he introduced a bunch of other errors), you can use the more limited StdMethod for n:

 instance GetEndpoint (Verb (n :: StdMethod) (s :: Nat) (ct :: [*]) a) (Verb ns ct a) 'True where getEndpoint _ _ _ _ server = server 

The complete code (compiling and even working as expected), can be found here .

Thanks again Karsten for this very quick help!

+5
source

Source: https://habr.com/ru/post/1246334/


All Articles