views:

194

answers:

2

Hi all,

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

+5  A: 

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 of Expression

It can't, given just what you posted.

Alexey Romanov
+4  A: 

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.

Hongfei