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

<%?

5 replies
sullivan-
Joined: 2009-10-13,
User offline. Last seen 39 weeks 5 days ago.
What's up with the <% operator used in type parameters? Why do I have to do
sealed abstract class ColumnViewPolicy[A <% AnalysisColumn] {
instead of
sealed abstract class ColumnViewPolicy[A <: AnalysisColumn] {
I originally had the latter, but I was getting some type errors that I didn't understand. Something like:
type arguments [A] do not conform to class ColumnViewPolicy's type parameter bounds [A <: org.broadinstitute.toolkit.core.domain.analysis.AnalysisColumn] [error] abstract class LeafColumnViewPolicy[A <: AnalysisColumn] extends ColumnViewPolicy[A] [error] ^
I googled about an found some references to the <% operator, and tried it, and it fixed my problem. But I sure would like to understand why!
Some of these Scala typing concepts are taking a while to sink in, but it's happening.
(More complete source code for above snippets)
Thanks! -John
H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: <%?
<% means "<: sometype or there is an implicit conversion so that converted <: sometype"

http://programming-scala.labs.oreilly.com/ch12.html


Am 01.07.2011 16:22, schrieb john sullivan:
u+gFLZMEQqeHScQ1EGaz6FG4WUQ [at] mail [dot] gmail [dot] com" type="cite"> What's up with the <% operator used in type parameters? Why do I have to do
sealed abstract class ColumnViewPolicy[A <% AnalysisColumn] {

instead of
sealed abstract class ColumnViewPolicy[A <: AnalysisColumn] {
I originally had the latter, but I was getting some type errors that I didn't understand. Something like:

type arguments [A] do not conform to class ColumnViewPolicy's type parameter bounds [A <: org.broadinstitute.toolkit.core.domain.analysis.AnalysisColumn] [error] abstract class LeafColumnViewPolicy[A <: AnalysisColumn] extends ColumnViewPolicy[A]
[error] ^
I googled about an found some references to the <% operator, and tried it, and it fixed my problem. But I sure would like to understand why!
Some of these Scala typing concepts are taking a while to sink in, but it's happening.
(More complete source code for above snippets)
Thanks! -John

Norbert Tausch
Joined: 2011-06-28,
User offline. Last seen 42 years 45 weeks ago.
Re: <%?
The first one uses a so-called view bound (http://programming-scala.labs.oreilly.com/ch12.html#ViewsAndViewBounds), the latter one an upper bound. View bounds work with additional implicit constructor/method-Arguments (evidence parameters) and are not the thing you want to have.

I don't see why there should be a problem. The following code compiles:
    class AnalysisColumn
    sealed abstract class ColumnViewPolicy[A <: AnalysisColumn]
    abstract class LeafColumnViewPolicy[A <: AnalysisColumn] extends ColumnViewPolicy[A]

Since your first class is sealed, the LeadColumnViewPolicy must be within the same source file: http://www.scala-lang.org/node/123
Best regards

Norbert Tausch

    
Am 01.07.2011 16:22, schrieb john sullivan:
u+gFLZMEQqeHScQ1EGaz6FG4WUQ [at] mail [dot] gmail [dot] com" type="cite"> What's up with the <% operator used in type parameters? Why do I have to do
sealed abstract class ColumnViewPolicy[A <% AnalysisColumn] {

instead of
sealed abstract class ColumnViewPolicy[A <: AnalysisColumn] {
I originally had the latter, but I was getting some type errors that I didn't understand. Something like:

type arguments [A] do not conform to class ColumnViewPolicy's type parameter bounds [A <: org.broadinstitute.toolkit.core.domain.analysis.AnalysisColumn] [error] abstract class LeafColumnViewPolicy[A <: AnalysisColumn] extends ColumnViewPolicy[A]
[error] ^
I googled about an found some references to the <% operator, and tried it, and it fixed my problem. But I sure would like to understand why!
Some of these Scala typing concepts are taking a while to sink in, but it's happening.
(More complete source code for above snippets)
Thanks! -John
sullivan-
Joined: 2009-10-13,
User offline. Last seen 39 weeks 5 days ago.
Re: <%?
Here is a version that gets the error I quoted above:
https://gist.github.com/1058724
I will continue to work on it to simplify the example down.
I can't see how anything implicit fits in here anywhere!
I will read that link, thanks.
On Fri, Jul 1, 2011 at 10:37 AM, Norbert Tausch <ntausch55 [at] gmail [dot] com> wrote:
The first one uses a so-called view bound (http://programming-scala.labs.oreilly.com/ch12.html#ViewsAndViewBounds), the latter one an upper bound. View bounds work with additional implicit constructor/method-Arguments (evidence parameters) and are not the thing you want to have.

I don't see why there should be a problem. The following code compiles:
    class AnalysisColumn
    sealed abstract class ColumnViewPolicy[A <: AnalysisColumn]
    abstract class LeafColumnViewPolicy[A <: AnalysisColumn] extends ColumnViewPolicy[A]

Since your first class is sealed, the LeadColumnViewPolicy must be within the same source file: http://www.scala-lang.org/node/123
Best regards

Norbert Tausch

    
Am 01.07.2011 16:22, schrieb john sullivan:
What's up with the <% operator used in type parameters? Why do I have to do
sealed abstract class ColumnViewPolicy[A <% AnalysisColumn] {

instead of
sealed abstract class ColumnViewPolicy[A <: AnalysisColumn] {
I originally had the latter, but I was getting some type errors that I didn't understand. Something like:

type arguments [A] do not conform to class ColumnViewPolicy's type parameter bounds [A <: org.broadinstitute.toolkit.core.domain.analysis.AnalysisColumn] [error] abstract class LeafColumnViewPolicy[A <: AnalysisColumn] extends ColumnViewPolicy[A]
[error] ^
I googled about an found some references to the <% operator, and tried it, and it fixed my problem. But I sure would like to understand why!
Some of these Scala typing concepts are taking a while to sink in, but it's happening.
(More complete source code for above snippets)
Thanks! -John



--
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
Bill Venners
Joined: 2008-12-18,
User offline. Last seen 31 weeks 5 days ago.
Re: <%?

Hi John,

Another tutorial on it is here:

http://www.artima.com/pins1ed/implicit-conversions-and-parameters.html#21.6

I think of <% as meaning "can be treated as".

Bill

On Fri, Jul 1, 2011 at 7:22 AM, john sullivan wrote:
> What's up with the <% operator used in type parameters? Why do I have to do
> sealed abstract class ColumnViewPolicy[A <% AnalysisColumn] {
> instead of
> sealed abstract class ColumnViewPolicy[A <: AnalysisColumn] {
> I originally had the latter, but I was getting some type errors that I
> didn't understand. Something like:
> type arguments [A] do not conform to class ColumnViewPolicy's type parameter
> bounds [A <: org.broadinstitute.toolkit.core.domain.analysis.AnalysisColumn]
> [error] abstract class LeafColumnViewPolicy[A <: AnalysisColumn] extends
> ColumnViewPolicy[A] [error] ^
> I googled about an found some references to the <% operator, and tried it,
> and it fixed my problem. But I sure would like to understand why!
> Some of these Scala typing concepts are taking a while to sink in, but it's
> happening.
> (More complete source code for above snippets)
> Thanks! -John

Ken McDonald
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
Re: <%?
Bill,
Thanks for your nice English description of <%--now it makes a lot more sense to me.
Ken

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