mardi 21 avril 2015

Scala : match case syntax vs => S?

 def phrase[T](p: Parser[T]) = new Parser[T] {
    def apply(in: Input) = lastNoSuccessVar.withValue(None) {
      p(in) match {
      case s @ Success(out, in1) =>
        if (in1.atEnd)
          s
        else
            lastNoSuccessVar.value filterNot { _.next.pos < in1.pos } getOrElse Failure("end of input expected", in1)
        case ns => lastNoSuccessVar.value.getOrElse(ns)
      }
    }
  }

The function above is found in Scala's source code.

What confuses me is : withValue's declaration is

def withValue[S](newval: T)(thunk: => S): S

then,

  • what is the meaning of => S ?

  • and what is the relationship with match case syntax ?

Aucun commentaire:

Enregistrer un commentaire