Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No instance for" error - but the instance exists (kinds did not match)

Tags:

haskell

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, which looks like that:

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

which looks exactly like the one ghc can not find. I am a bit confused right now.

Full code can be found here:

  • Instance definition - right at the bottom of the file.
  • File triggering the error - relevant code also at the bottom.

Any clues? Thanks a lot for any hints!

like image 781
robert Avatar asked Apr 03 '16 10:04

robert


1 Answers

The given instance has default kind '*' for n s ct and a. Either use poly kinds as for n or the right concrete kinds:

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

The correct instance would look like this:

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

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

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

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

Thanks again Carsten for this really quick help!

like image 73
robert Avatar answered Sep 28 '22 08:09

robert