1 Mar 2009 10:43
Re: Equality and case objects
On Sat, Feb 28, 2009 at 12:15 AM, David MacIver <david.maciver@...> wrote: > On Fri, Feb 27, 2009 at 11:11 PM, Lex Spoon <lex@...> wrote: >> >> On Feb 28, 2009, at 12:23 AM, David MacIver wrote: >>> >>> So the match expression would be translated to: >>> >>> x match { >>> case (_: C) => ... >>> case (_: object O) => ... >>> case y if (y == this.V) => ... >>> } >>> >>> What's your opinion on this? >>> >>> I agree that the errors caused by this case are somewhat problematic, but >>> I'm not sure they occur commonly enough for it to be worth the spec >>> complication, particularly if (as suggested above) matching on inner objects >>> of a class becomes a warning. I'm also a little concerned that it's not >>> caught statically. If x is known to come from a different instance of Outer, >>> why is this not being rejected as the types of the matches not being >>> subtypes of the matched object? Between that and warning on matching inner >>> case classes I think that would catch most of the use cases adequately. >> >> This is my initial reaction, too, but more broadly. How important is it >> to support custom equality methods for case class hierarchies? > > I think it's pretty important. Case classes are basically used for creating > custom interesting data structures, and it can be unnecessarily difficult to(Continue reading)
Back on the previous subject, what should this code do?
object Test {
def foo(x : Any) : Any = {
case class Foo();
println(x match {
case Foo() => true
case _ => false;
})
new Foo;
}
def main(args : Array[String]){
foo(foo(new AnyRef))
}
}
The two Foos come from different invocations of the method (which are
morally equivalent to different instances of an enclosing class in my
opinion), but they still match as eachother. This seems wrong, but I'm
not sure what to suggest as an alternative.
On Sun, Mar 1, 2009 at 1:15 PM, martin odersky <
RSS Feed