类型别名不匹配

时间:2019-03-19 20:11:06

标签: scala

我有以下代码,无法编译:

object PcpProtocol {

  private type PcpHead = String
  private type PcpBody = String
  private type PcpValidity[A] = Either[String, A]
  private val PcpIndicator = "pcp-channel:apc"

  implicit val pcpProtocol: Protocol[PcpProtocol] = new Protocol[PcpProtocol] {
    override def encode(text: String): PcpProtocol = ???

    override def decode(msg: PcpProtocol): String = ???
  }

  private val validatePcp: PcpValidity[PcpHead] = (head: String) => {
    if (head.contains(PcpIndicator)) {
      Right(head)
    } else {
      Left("The message does not correspond to SAP PCP protocol")
    }
  }
}

错误消息显示:

 type mismatch;
[error]  found   : String => scala.util.Either[String,String]
[error]  required: com.sweetsoft.PcpProtocol.PcpValidity[com.sweetsoft.PcpProtocol.PcpHead]
[error]     (which expands to)  scala.util.Either[String,String]
[error]   private val validatePcp: PcpValidity[PcpHead] = (head: String) => {  

我无法弄清错误。怎么了?

0 个答案:

没有答案