haskell-servant / servant-snap

Snap port of servant-server (WIP)
Other
28 stars 18 forks source link

Support servant-0.14/0.15 #20

Closed antislava closed 5 years ago

antislava commented 6 years ago

There have been quite a few changes in the servant streaming API (in particular, the type of (To)StreamGenerator) since servant-0.13. See https://github.com/haskell-servant/servant/blob/master/servant/CHANGELOG.md

This straightforward modification of the HasServer instance declaration for Stream https://github.com/antislava/servant-snap/commit/3f899473a12890777caa226ab249498ab5442837#diff-d8a4d65c798fd5234e7aee3f9b2509bf was sufficient for the library to typecheck but the streaming component of the example greet.hs API stopped compiling:

example/greet.hs:86:10: error:
    • Couldn't match type ‘Servant.Server.Internal.ServerT
                             (Stream 'GET 200 NetstringFraming JSON (StreamGenerator Greet))
                             '[]
                             (Handler App App)’
                     with ‘m0 (StreamGenerator Greet)’
      Expected type: Server
                       (TestApi AppHandler StreamGenerator) '[] AppHandler
        Actual type: (Text -> Maybe Bool -> AppHandler Greet)
                     :<|> ((Text -> Maybe Bool -> Handler App App Greet)
                           :<|> ((Greet -> Handler App App Greet)
                                 :<|> ((Text -> Handler App App ())
                                       :<|> (m0 (StreamGenerator Greet)
                                             :<|> (Handler App App () :<|> Handler App App ())))))
      The type variable ‘m0’ is ambiguous
    • In the expression:
        helloH
          :<|>
            helloH'
              :<|>
                postGreetH
                  :<|>
                    deleteGreetH :<|> doStream :<|> serveDirectory "static" :<|> doRaw
      In an equation for ‘server’:
          server
            = helloH
                :<|>
                  helloH'
                    :<|>
                      postGreetH
                        :<|>
                          deleteGreetH :<|> doStream :<|> serveDirectory "static" :<|> doRaw
            where
                helloH :: Text -> Maybe Bool -> AppHandler Greet
                helloH name Nothing = helloH name (Just False)
                helloH name (Just False) = return . Greet $ "Hello, " <> name
                helloH name (Just True)
                  = return . Greet . toUpper $ "Hello, " <> name
                helloH' :: Text -> Maybe Bool -> (Handler App App) Greet
                helloH' name _
                  = with auth
                      $ do cu <- currentUser
                           ....
                ....
    • Relevant bindings include
        doStream :: m0 (StreamGenerator Greet)
          (bound at example/greet.hs:110:9)
   |
86 | server = helloH
   |          ^^^^^^...
benkolera commented 5 years ago

I would like to undertake the work to get a PR in to bump servant support up to 0.14 as I would really like to have this to be able to use servant inside an obelisk project (which is snap based).

Is such a PR likely to be accepted or have you given up on the idea of servant-snap? If the latter, can you shed some idea on why so I don't make the same mistakes getting servant into obelisk? :slightly_smiling_face:

@antislava : I see that you have a fork that has a working version that supports 0.14 but has the examples and tests disabled. Can you remember why and do have an estimate of how much work it would be to get the tests and example building too? Was it the compilation failure on the Streaming side? I'm happy to run with your work, try to figure out the error and get this into a PR if that's OK with you (and I'm able to figure it out, of course :wink:).

phadej commented 5 years ago

@benkolera We'd like to do https://github.com/haskell-servant/servant/issues/1166, as updating servant-snap is more or less

We did this exercise for servant-client, but not for the server yet.

imalsogreg commented 5 years ago

@benkolera Awesome! I'd be very happy to get a PR that gets us compatible with servant-0.14/0.15!

Re: @phadej's idea about factoring servant-server into core, -wai, and -snap parts similar to what happened with servant-client - agreed, that would be really nice to have. And it should be less difficult to implement now that servant-server handlers are parameterized by monad.