Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of additional colon in Scala class parametrization

What does [A : Manifest : WireFormat] mean in the following code? It's from com.nicta.scoobi.TextInput (available on github). It doesn't seem to be any of the usual type bounds.

  def fromDelimitedTextFile[A : Manifest : WireFormat]       (path: String, sep: String = "\t")       (extractFn: PartialFunction[List[String], A])     : DList[A] = {      val lines = fromTextFile(path)     lines.flatMap { line =>       val fields = line.split(sep).toList       if (extractFn.isDefinedAt(fields)) List(extractFn(fields)) else Nil     }   } 

Where can I find more information about this topic?

like image 632
chris Avatar asked Oct 08 '12 17:10

chris


1 Answers

This is called a context bound. They are syntactic sugar for an implicit parameter list:

def meth[A : ContextBound1 : ContextBoundN](a: A)  // ==>  def meth[A](a: A)(implicit evidence: ContextBound1[A], ContextBoundN[A]) 

If there are multiple context bounds from 1 to N, they are all translated into the same parameter list. See this question for a more detailed explanation about how they work and for what they are useful.

To find such symbols it is useful to read the StackOverflow Scala Tutorial.

like image 135
kiritsuku Avatar answered Oct 06 '22 06:10

kiritsuku