I have the following model:
sealed trait MyRequest {
type Response <: MyResponse
}
sealed trait MyResponse {
type Request <: MyRequest
}
case class SayHelloRequest(name: String) extends MyRequest {
override type Response = SayHelloResponse
}
case class SayHelloResponse(greeting: String) extends MyResponse {
override type Request= SayHelloRequest
}
...
Is there some way, at the type level, I can enforce that the request/response pair match together? So if SayHelloRequest has a response type SayHelloResponse then SayHelloResponse must have a request type of SayHelloRequest.
Something like:
MyRequest#Response#Request =:= MyRequest
MyResponse#Request#Response =:= MyResponse
Try F-bounds
or a type class (and F-bounds)
https://tpolecat.github.io/2015/04/29/f-bounds.html