Skip to content

Kinder type checking#890

Merged
alpmestan merged 1 commit intohaskell-servant:masterfrom
mgsloan:kinder-type-checking
Jan 18, 2018
Merged

Kinder type checking#890
alpmestan merged 1 commit intohaskell-servant:masterfrom
mgsloan:kinder-type-checking

Conversation

@mgsloan
Copy link
Copy Markdown
Contributor

@mgsloan mgsloan commented Jan 17, 2018

The resulting errors are ludicrously better with ( :: *) signatures:

Breaking the greet example by doing

  :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON]

instead of

  :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] NoContent

Before yielded

    /home/mgsloan/oss/haskell/servant/servant-docs/example/greet.hs:94:5: error:
        • Could not deduce: Servant.API.TypeLevel.Or
                              (Servant.API.TypeLevel.IsIn
                                 ("greet" :> (Capture "greetid" Text :> Delete '[JSON] NoContent))
                                 ("hello"
                                  :> (Capture "name" Text
                                      :> (QueryParam "capital" Bool :> Get '[JSON, PlainText] Greet))))
                              (Servant.API.TypeLevel.Or
                                 (Servant.API.TypeLevel.IsIn
                                    (Capture "greetid" Text :> Delete '[JSON] NoContent)
                                    (ReqBody '[JSON] Greet
                                     :> Post '[JSON] (Headers '[Header "X-Example" Int] Greet)))
                                 (Servant.API.TypeLevel.IsIn
                                    (Capture "greetid" Text :> Delete '[JSON] NoContent)
                                    (Capture "greetid" Text :> Maybe)))
            arising from a use of ‘extraInfo’
        • In the expression:
            extraInfo
              (Proxy ::
                 Proxy ("greet"
                        :> (Capture "greetid" Text :> Delete '[JSON] NoContent)))
          In the expression:
            extraInfo
              (Proxy ::
                 Proxy ("greet"
                        :> (Capture "greetid" Text :> Delete '[JSON] NoContent)))
              $ defAction & headers <>~ ["unicorns"]
                  & notes
                      <>~
                        [DocNote "Title" ["This is some text"],
                         DocNote "Second secton" ["And some more"]]
          In an equation for ‘extra’:
              extra
                = extraInfo
                    (Proxy ::
                       Proxy ("greet"
                              :> (Capture "greetid" Text :> Delete '[JSON] NoContent)))
                    $ defAction & headers <>~ ["unicorns"]
                        & notes
                            <>~
                              [DocNote "Title" ["This is some text"],
                               DocNote "Second secton" ["And some more"]]
       |
    94 |     extraInfo (Proxy :: Proxy ("greet" :> Capture "greetid" Text :> Delete '[JSON] NoContent)) $
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    /home/mgsloan/oss/haskell/servant/servant-docs/example/greet.hs:108:13: error:
        • No instance for (HasDocs Maybe) arising from a use of ‘docsWith’
        • In the expression:
            docsWith defaultDocOptions [intro1, intro2] extra testApi
          In an equation for ‘docsGreet’:
              docsGreet
                = docsWith defaultDocOptions [intro1, intro2] extra testApi
        |
    108 | docsGreet = docsWith defaultDocOptions [intro1, intro2] extra testApi
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

And now yields

    /home/mgsloan/oss/haskell/servant/servant-docs/example/greet.hs:84:45: error:
        • Expecting one more argument to ‘Delete '[JSON]’
          Expected a type, but ‘Delete '[JSON]’ has kind ‘* -> *’
        • In the second argument of ‘:>’, namely ‘Delete '[JSON]’
          In the second argument of ‘:>’, namely
            ‘Capture "greetid" Text :> Delete '[JSON]’
          In the second argument of ‘:<|>’, namely
            ‘"greet" :> (Capture "greetid" Text :> Delete '[JSON])’
       |
    84 |   :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON]
       |                                             ^^^^^^^^^^^^^^

@mgsloan mgsloan force-pushed the kinder-type-checking branch 2 times, most recently from 7d2f587 to 6df109c Compare January 17, 2018 11:21
@alpmestan
Copy link
Copy Markdown
Contributor

alpmestan commented Jan 17, 2018

Wow, the error really is a lot nicer! Great. If the CI is green, I'm definitely in favor of merging this. @phadej no objection?

@alpmestan
Copy link
Copy Markdown
Contributor

@mgsloan hah. turns out there is a test that uses ReqBody with something of kind Bool, see CI error. any reasonable fix will do.

@mgsloan mgsloan force-pushed the kinder-type-checking branch from 6df109c to 05243fc Compare January 17, 2018 14:00
@mgsloan
Copy link
Copy Markdown
Contributor Author

mgsloan commented Jan 17, 2018

@alpmestan Funny! The type in the test was wrong, but it doesn't matter for what the test is testing.

@mgsloan
Copy link
Copy Markdown
Contributor Author

mgsloan commented Jan 17, 2018

I don't think the CI failures have anything to do with this PR anymore.

@phadej
Copy link
Copy Markdown
Contributor

phadej commented Jan 17, 2018

@mgsloan can you rebase on top of master, that should make travis green

@mgsloan mgsloan force-pushed the kinder-type-checking branch from 05243fc to 7e0ad51 Compare January 18, 2018 05:16
@mgsloan
Copy link
Copy Markdown
Contributor Author

mgsloan commented Jan 18, 2018

Rebased! Let's hope CI is satisfied.

@alpmestan alpmestan merged commit 345dc8a into haskell-servant:master Jan 18, 2018
@alpmestan
Copy link
Copy Markdown
Contributor

Aaaaand CI is happy. Thanks @mgsloan!

@mgsloan
Copy link
Copy Markdown
Contributor Author

mgsloan commented Jan 18, 2018

Welcome, thanks for reviewing!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants