Why are Map and Set aliased in scala.Predef? -
9 times out of 10, using map
, set
behave expect would, unexpectedly hit
error: type mismatch; [info] found : scala.collection.set[string] [info] required: set[string]
as example, repl:
scala> case class calculator[+t](name: string, parameters: set[string]) defined class calculator scala> val binding=map.empty[string, string] binding: scala.collection.immutable.map[string,string] = map() scala> calculator("hello",binding.keyset) <console>:9: error: type mismatch; found : scala.collection.set[string] required: set[string] calculator("hello",binding.keyset) ^
i think understand error, is, function call on aliased types return actual types.
and seems me solution import un-aliased types. upon every other file in project generate type mismatch errors, have import in each file. leads question ask in title -- purpose of alias in predef, if need import actual package anyway?
is understanding flawed, or use case not typical one, or both?
you have misdiagnosed problem. isn't doesn't recognize type alias same type aliasing. it's type alias scala.collection.immutable.set , not same scala.collection.set.
edit: way, thought i'd fixed this, evinced comment in type diagnostics:
... also, if * type error because of conflict between 2 identically named * classes , 1 in package scala, qualify name 1 * need not deduce why "java.util.iterator" , "iterator" don't match.
apparently needs more work.
edit 7/17/2010: ok, took me shockingly long time, @ least says hard misunderstand.
files/neg/type-diagnostics.scala:4: error: type mismatch; found : scala.collection.set[string] required: scala.collection.immutable.set[string] def f = calculator("hello",binding.keyset) ^
Comments
Post a Comment