Underscore as a type parameter basically means „I don't care what type is there“, so naming it does not make sense.
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def blah(...): ... = { def withSth[A](sth: SomeGenericClass[A]): ... = 42 // in this body you can use A to talk about the existential withSth(giveMeSth()) }
-- Stephen Compall "^aCollection allSatisfy: [:each|aCondition]": less is better |
That reminds me, you can use a variable type pattern (lower case type argument to a type pattern) in a pattern match to name the existential.
scala> val x: Some[_] = Some("a")
x: Some[_] = Some(a)
scala> x match { case sa: Some[a] => var temp: a = sa.get; temp = sa.get; temp }
res3: Any = a
On Sat, 2014-04-26 at 18:37 +0200, Jason Zaugg wrote:Whoa. When did that happen?
scala> x match { case sa: Some[a] => var temp: a = sa.get; temp = sa.get; temp }res3: Any = a
A parameterized type pattern T[a1,...,an], where the ai are type variable patterns or wildcards _. This type pattern matches all values which match T for some arbitrary instantiation of the type variables and wildcards. The bounds or alias type of these type variable are determined as described in (§8.3).
A type variable pattern is a simple identifier which starts with a lower case letter. However, the predefined primitive type aliases unit, boolean, byte, short, char, int, long, float, and double are not classified as type variable patterns.
scala> x match { case sa: Some[a] => var temp: a = sa.get; temp = sa.get; temp }res3: Any = a
Whoa. When did that happen?