bmanc
bmanc

Reputation: 135

Trying to understand the function signature for Scala parsers e.g. def rep[T](p: => Parser[T]): Parser[List[T]]

In the following Parser definition

def  rep[T](p: => Parser[T]): Parser[List[T]]

I see the argument is a function. There is no type after p:, so what is it's type?

Thanks

Basu

Upvotes: 1

Views: 332

Answers (2)

virtualeyes
virtualeyes

Reputation: 11237

Someone correct me if I'm wrong here, but I believe with by-name parameters the type is the return type, in this case, Parser[T]

Basically what you see (return type) is what you pass into it

Upvotes: 1

Destin
Destin

Reputation: 1214

p is actually not a function. An unpreceded => in the type description means that the argument is passed by name. Basically, it is not evaluated until it is used in the method, and it is evaluated every time that it is used in the method. Please see my answer here for a bit more info.

Upvotes: 4

Related Questions