Giter Site home page Giter Site logo

Comments (4)

alpmestan avatar alpmestan commented on June 8, 2024 1

Right, when type families conflict that much their answers have to "be compatible".

I'm thinking it might be worth putting all our brainpower on haskell-servant/servant#841 instead of fighting that kind of problem =) If we re-engineer Verb to allow us to specify an (optional) list of "sad paths" in addition to the happy path that it knows about at the moment, we might get the best of both worlds and get rid once and for all of all those overlapping instances, if we play our moves right.

from servant-checked-exceptions.

cdepillabout avatar cdepillabout commented on June 8, 2024

I think this should be mostly fixed with #6.

I think the only thing left is to handle apis that set Headers.

from servant-checked-exceptions.

cdepillabout avatar cdepillabout commented on June 8, 2024

Today I tried to add support for handling APIs that set Headers, but I have run into some difficulty.

Here is the existing instance for Throwing:

-- | When @'Throwing' es@ comes before a 'Verb', change it into the same 'Verb'
-- but returning an @'Envelope' es@.
instance
    {-# OVERLAPPABLE #-}
    (HasServer (Verb method status ctypes (Envelope es a)) context) =>
    HasServer (Throwing es :> Verb method status ctypes a) context where

  type ServerT (Throwing es :> Verb method status ctypes a) m =
    ServerT (Verb method status ctypes (Envelope es a)) m

  route
    :: Proxy (Throwing es :> Verb method status ctypes a)
    -> Context context
    -> Delayed env (ServerT (Verb method status ctypes (Envelope es a)) Handler)
    -> Router env
  route _ = route (Proxy :: Proxy (Verb method status ctypes (Envelope es a)))

I tried to add an additional instance for use with Headers that looks like this:

instance
    {-# OVERLAPPING #-}
    (HasServer (Verb method status ctypes (Headers h (Envelope es a))) context) =>
    HasServer (Throwing es :> Verb method status ctypes (Headers h a)) context where

  type ServerT (Throwing es :> Verb method status ctypes (Headers h a)) m =
    ServerT (Verb method status ctypes (Headers h (Envelope es a))) m

  route
    :: Proxy (Throwing es :> Verb method status ctypes (Headers h a))
    -> Context context
    -> Delayed
         env
         ( ServerT
           (Verb method status ctypes (Headers h (Envelope es a)))
           Handler
         )
    -> Router env
  route _ =
    route (Proxy :: Proxy (Verb method status ctypes (Headers h (Envelope es a))))

However, this is failing with the following error:

src/Servant/Checked/Exceptions/Internal/Servant/Server.hs:61:8: error:
    Conflicting family instance declarations:

      forall k1 a (ctypes :: [*]) (status :: Nat) (method :: k1) (es :: [*]) (m :: * -> *).
        ServerT (Throwing es :> Verb method status ctypes a) m =
            ServerT (Verb method status ctypes (Envelope es a)) m
      -- Defined at src/Servant/Checked/Exceptions/Internal/Servant/Server.hs:61:8

      forall k1 a (h :: [*]) (ctypes :: [*]) (status :: Nat) (method :: k1) (es :: [*]) (m :: * -> *).
        ServerT (Throwing es :> Verb method status ctypes (Headers h a)) m =
            ServerT (Verb method status ctypes (Headers h (Envelope es a))) m
      -- Defined at src/Servant/Checked/Exceptions/Internal/Servant/Server.hs:80:8

Here are some links related to this error:

It doesn't look like there is an easy way to fix this.

from servant-checked-exceptions.

cdepillabout avatar cdepillabout commented on June 8, 2024

It looks like servant-auth defines a single type class and related type family for determining how to modify the response type to add headers:

https://www.stackage.org/haddock/lts-13.26/servant-auth-server-0.4.4.0/Servant-Auth-Server.html#t:HasServer

https://www.stackage.org/haddock/lts-13.26/servant-auth-server-0.4.4.0/Servant-Auth-Server-Internal-AddSetCookie.html#t:AddSetCookies

I wonder if something similar to this could be adopted for servant-checked-exceptions.

from servant-checked-exceptions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.