Skip to content

Stuck on no instance for KnownSymbol #1

Description

@magthe

This isn't so much an issue as a request for help.

I have the following

import Data.ByteString.Lazy (ByteString)
import Network.Wreq qualified as W

class Monad m => MonadHttpClient m where
  mHttpGet :: String -> m (W.Status, ByteString)
  mHttpPost :: W.Postable a => String -> a -> m (W.Status, ByteString)

which I attempt to write two simple tests for. The first, for mHttpGet, works fine:

import Test.HMock
import Test.HMock.TH (makeMockable)
import Test.Tasty
import Test.Tasty.HUnit

makeMockable ''MonadHttpClient

httpGetTest :: TestTree
httpGetTest = testCase "Get Test" $ do
  (s, b) <- runMockT $ do
    expect $ MHttpGet "url" |-> (status200, "")
    mHttpGet "url"
  s @=? status200
  b @=? "c"

The second, for mHttpPost, won't type check, and I don't know how to solve it:

httpPostTest :: TestTree
httpPostTest = testCase "Post Test" $ do
  (s, b) <- runMockT $ do
    expect $ MHttpPost "url" ("hello" :: ByteString) |-> ()
    mHttpPost "url" ("hello" :: ByteString)
  s @=? status200
  b @=? "a"

The errors are

test/HttpTest.hs:44:5: error:
    • No instance for (GHC.TypeLits.KnownSymbol name0)
        arising from a use of ‘expect’
    • In a stmt of a 'do' block:
        expect $ MHttpPost "url" ("hello" :: ByteString) |-> ()
      In the second argument of ‘($)’, namely
        ‘do expect $ MHttpPost "url" ("hello" :: ByteString) |-> ()
            mHttpPost "url" ("hello" :: ByteString)’
      In a stmt of a 'do' block:
        (s, b) <- runMockT
                    $ do expect $ MHttpPost "url" ("hello" :: ByteString) |-> ()
                         mHttpPost "url" ("hello" :: ByteString)
   |
44 |     expect $ MHttpPost "url" ("hello" :: ByteString) |-> ()
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

test/HttpTest.hs:44:14: error:
    • No instance for (Expectable
                         cls0
                         name0
                         IO
                         ()
                         (Action
                            MonadHttpClient
                            "mHttpPost"
                            b0
                            (Network.HTTP.Types.Status.Status, ByteString)))
        arising from a use of ‘|->’
    • In the second argument of ‘($)’, namely
        ‘MHttpPost "url" ("hello" :: ByteString) |-> ()’
      In a stmt of a 'do' block:
        expect $ MHttpPost "url" ("hello" :: ByteString) |-> ()
      In the second argument of ‘($)’, namely
        ‘do expect $ MHttpPost "url" ("hello" :: ByteString) |-> ()
            mHttpPost "url" ("hello" :: ByteString)’
   |
44 |     expect $ MHttpPost "url" ("hello" :: ByteString) |-> ()
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm not at all sure what this even means, but I'm guessing it's related to the Postable a constraint in some way.

Any help and/or insights would be very helpful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions