This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Can't we all just get a Long?

2 replies
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.

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.

Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 3 days ago.
Re: Can't we all just get a Long?
You weren't an octopus in a past life, by any chance?I kept expecting you to move onto feet...

2010/1/9 Paul Phillips <paulp@improving.org>
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.

--
Paul Phillips      | On two occasions, I have been asked, 'Mr. Babbage, if you
Stickler           | put into the machine wrong figures, will the right answers
Empiricist         | come out?' I am not able to rightly apprehend the kind of
i'll ship a pulp   | confusion of ideas that could provoke such a question.



--
Kevin Wright

mail/google talk: kev.lee.wright@googlemail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
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

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland