Reputation: 117
I'm a beginner in Scala and I'm just curious about how Scala handles the type inference for this code snippet
trait Expression { .... }
def eval (binding : String => Boolean) : Expression => Boolean
I understand that binding is a function that converts String
to Boolean
, but why binding
at the same time could be declared as a member of Expression
? is it implicitly converted? How does it work?
Sorry if my question is a bit confusing
Thanks so much :D
Upvotes: 1
Views: 436
Reputation: 143
I think the key point is that, function eval
returns a function, whose type is Function2[Expression, Boolean]
.
It's more clear to say:
def eval (binding : String => Boolean) : (Expression => Boolean)
There is no direct relationship between binding
and Expression
.
Upvotes: 4
Reputation: 170899
There is absolutely no type inference going on here, as Jörg W Mittag says.
def eval (binding : String => Boolean) : Expression => Boolean
is simply an abstract method declaration (abstract because it doesn't have a body). It can be implemented in different ways, depending on the definition of Expression
.
why
binding
at the same time could be declared as a member ofExpression
It can't, given just what you posted.
Upvotes: 5