- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Disjoint View Bounds
Mon, 2009-03-16, 02:58
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
Wed, 2009-05-20, 19:37
#2
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
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