- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Can't we all just get a Long?
Sat, 2010-01-09, 21:26
This has always been a runtime match error:
val (x: Int, y: Long) = (5, 5)
Now with weak conformance it has become even more jarring, and it is
tempting to say it should match now. OTOH if you wrote something like
this:
def foo(x: Any) = x match {
case x: Long => 1
case x: Int => 2
}
...you'd probably be surprised it didn't work. OTOOH, if that failed
with "unreachable code" you'd know you could get what you want with a
little reordering. OTOOOH, since List(1, 1L) is List[Long] and
List(List(1), List(1L)) List[List[AnyVal]], maybe the best thing is to
accept life as it is and walk the earth.
Sun, 2010-01-10, 12:47
#2
Re: Can't we all just get a Long?
On Sat, Jan 9, 2010 at 9:25 PM, Paul Phillips wrote:
> This has always been a runtime match error:
>
> val (x: Int, y: Long) = (5, 5)
>
> Now with weak conformance it has become even more jarring, and it is
> tempting to say it should match now. OTOH if you wrote something like
> this:
>
> def foo(x: Any) = x match {
> case x: Long => 1
> case x: Int => 2
> }
>
> ...you'd probably be surprised it didn't work. OTOOH, if that failed
> with "unreachable code" you'd know you could get what you want with a
> little reordering. OTOOOH, since List(1, 1L) is List[Long] and
> List(List(1), List(1L)) List[List[AnyVal]], maybe the best thing is to
> accept life as it is and walk the earth.
>
Yes, I agree. The problem is that weak conformance is still just a
conversion and not based on subtyping, whereas pattern matching is
based on subtyping. If we declare
that 5 is a Long, then we'd have problems arguing that List(5) is not
a List[Long]!
So let's accept life as it is and wlak the earth.
Cheers
2010/1/9 Paul Phillips <paulp@improving.org>
--
Kevin Wright
mail/google talk: kev.lee.wright@googlemail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda