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

Disjoint View Bounds

2 replies
Mitch Blevins
Joined: 2009-03-16,
User offline. Last seen 42 years 45 weeks ago.

I'd like to use disjoint view bounds in Scala, and can with this
approach: http://cleverlytitled.blogspot.com/2009/03/disjoint-bounded-views-redux....

However, it sure would be convenient if the calling code did not have
to import the supporting object. I'm interested if people think that
it would be too intrusive to include the type of "or" in the Predef?
What about something else, like "OrType" or "||" or
"EitherOfTheseIsFine"?

Example usage:

def bar[T <% Int or String or Double](t: Option[T]) = {
t match {
case Some(x: Int) => println("processing Int: " + x)
case Some(x: String) => println("processing String: " + x)
case Some(x: Double) => println("processing Double: " + x)
case None => println("empty and I don't care the type")
}
}

-Mitch

Landei
Joined: 2008-12-18,
User offline. Last seen 45 weeks 4 days ago.
Re: Disjoint View Bounds

Mitch Blevins wrote:
>
> I'd like to use disjoint view bounds in Scala, and can with this
> approach:
> http://cleverlytitled.blogspot.com/2009/03/disjoint-bounded-views-redux....
>
> However, it sure would be convenient if the calling code did not have
> to import the supporting object. I'm interested if people think that
> it would be too intrusive to include the type of "or" in the Predef?
> What about something else, like "OrType" or "||" or
> "EitherOfTheseIsFine"?
>
> Example usage:
>
> def bar[T <% Int or String or Double](t: Option[T]) = {
> t match {
> case Some(x: Int) => println("processing Int: " + x)
> case Some(x: String) => println("processing String: " + x)
> case Some(x: Double) => println("processing Double: " + x)
> case None => println("empty and I don't care the type")
> }
> }
>
> -Mitch
>

Hi!

I like the idea. How is the performance?

Having this feature in Predef could be quite useful, and maybe it could be
supported by compiler magic in the distant future.

I like the short "or" as name, but I'm not sure if name clashes are lurking
around the corner. Did you consider a single "|" (which isn't used as
frequently as "||", and has a cool "haskellish" look) ?

Cheers,
Daniel

Landei
Joined: 2008-12-18,
User offline. Last seen 45 weeks 4 days ago.
Re: Disjoint View Bounds

Mitch Blevins wrote:
>
> I'd like to use disjoint view bounds in Scala, and can with this
> approach:
> http://cleverlytitled.blogspot.com/2009/03/disjoint-bounded-views-redux....
>
> However, it sure would be convenient if the calling code did not have
> to import the supporting object. I'm interested if people think that
> it would be too intrusive to include the type of "or" in the Predef?
> What about something else, like "OrType" or "||" or
> "EitherOfTheseIsFine"?
>
> Example usage:
>
> def bar[T <% Int or String or Double](t: Option[T]) = {
> t match {
> case Some(x: Int) => println("processing Int: " + x)
> case Some(x: String) => println("processing String: " + x)
> case Some(x: Double) => println("processing Double: " + x)
> case None => println("empty and I don't care the type")
> }
> }
>
> -Mitch
>
>

Hi,

everybody seems to contribute 2.8 wishlists these days (is it X-mas
already??), so I want to bring up disjoint view bounds again. What do you
think, is there some space left in Predef for that?

Cheers,
Daniel

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