Open lortabac opened 5 years ago
Delayed
rearranges things (i.e. servant-server
checks things in different order than written in the type, for performance reasons, e.g. parsing ReqBody
very last); so the dependent server is indeed a puzzle.
I have no idea if you can do dependent servers with Delayed
, and whether you need to modify it (and how much).
I wonder if Delayed could be modeled as some kind of state machine over the routing information using something ala https://github.com/coot/free-category/blob/master/examples/src/LoginStateMachine.hs , that pops off the correct bits of information from the type-level representation...
food for thought indeed
This would be a nice thing to investigate once I get around to extracting a servant-server-core
package with just the routing machinery and everything relevant that's wai/warp agnostic in general. That'd probably make it easier, abstracting away from a lot of irrelevant details. I've unfortunately been quite busy...
I am trying to adapt the ideas in https://www.well-typed.com/blog/2015/12/dependently-typed-servers/ to more recent versions of
servant-server
.In
servant-server-0.4
in theroute
method you could access the request, parse the path segment, do dependent pattern-matching on the decoded value and then callroute
recursively. In recent versions you cannot access the request directly anymore, but have to work with aDelayed
, therefore the same technique is not applicable.For an example of where I am stuck, you can look at this experimental branch of my
versioning
library: https://github.com/lortabac/versioning/blob/servant-dependent-i-am-stuck/versioning-servant/src/Versioning/Servant/Dependent.hs