But z is for value: B1, and B1 in this case is an unapplied function from String to String.
-------------------------------------
Johannes Rudolph<
johannes.rudolph@...> wrote:
On Tue, Jul 7, 2009 at 2:37 PM, Jem<
jem.mawson@...> wrote:
> Thanks Johannes.
> Surely both cases are typed. seed is a typed map:
>> val seed = Map.empty[Int, (String)=>String]
Right, but there is no expected return type in the second case. To
make it work you can change the second case to
scala> (seed(1) = z):Map[Int,String=>String]
res2: Map[Int,(String) => String] = Map(1 -> <function>)
which, of course, is ridicously verbose but shows the difference the
context can make. This is still only an observation not an
explanation.
Trying an explanation:
seed(1) = z is syntactic sugar for seed.update(1,z). And Map.update is
defined as
def update [B1 >: B](key : A, value : B1) : Map[A, B1]
So the type of the value may change the type of the result. This may
explain the dependence on the presence of a fixed return type. Perhaps
the syntax without the underscore is only valid, if the type can be
fully infered?!?
--
Johannes
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net