나는 스칼라에 servant-server
포트에서 작업 중입니다. 아이디어는 typecass 해상도를 사용하여 요청을 처리 할 수있는 함수를 유도 적으로 구축하는 것입니다. 나는 꽤 이상하게 추측 할 수없는 이상한 추론을하고있다.스칼라는 유도 적으로 빌드 된 경로 종속 유형을 추측 할 수 없습니다.
val foo = implicitly[HasServer[Int :> Unit]]
implicitly[=:=[Int => String, foo.ServerT]]
오류는 다음과 같습니다 : 그러나
servant.scala:33: error:
Cannot prove that Int => String =:= Main.$anon.Servant.foo.ServerT.
, 내가 통해 직접 HasServer[Int :> Unit]
를 인스턴스화하는 경우가 이 컴파일 위의와
object Servant {
class :>[Path, A]
trait HasServer[A] {
type ServerT
def route(a: ServerT): String
}
implicit val unitServer = new HasServer[Unit] {
type ServerT = String
def route(str: ServerT): String = str
}
implicit def subServer[A, Sub](implicit sub: HasServer[Sub]) = new HasServer[A :> Sub] {
type ServerT = A => sub.ServerT
def route(handler: ServerT): String = "handler"
}
}
는, 다음은 컴파일에 실패 :
val foo = new HasServer[Int :> Unit] {
type ServerT = Int => unitServer.ServerT
def route(handler: ServerT): String = handler(10)
}
어떻게 이것을 컴파일 할 수 있습니까? 감사!
저는 재미 있어요, 저는 2 년 동안 Aux 트릭을 사용했고, 결코 암묵적으로 의존하지 않았고, 암묵적으로 당신이 묻는 것보다 더 정확한 타입을 반환하지 않는다는 것을 알게되었습니다.) – mandubian