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

Existential types

3 replies
edmondo1984
Joined: 2011-09-14,
User offline. Last seen 28 weeks 3 days ago.
Dear all,
I have an issue with existential types I can't solve.
abstract class CurveTermStructureExtractionInput[T <: TermStructure](  val collections:SingleTermStructureArbitrageableCollection[_,T,_] *) {
collections.foldLeft(0){ case (item,coll) =>item+coll.size}
}

error: type arguments [_$1,T,_$2] do not conform to trait SingleTermStructureArbitrageableCollection's type parameter bounds [T <: com.gottex.gottware.common.datamodels.finance.securities.impl.SecurityImpl,X <: com.gottex.gottware.common.datamodels.finance.math.termstructure.representation.TermStructure,+Repr <: com.gottex.gottware.common.datamodels.finance.collections.specialized.termstructures.SingleTermStructureArbitrageableCollection[T,X,Repr]] collections.foldLeft(position) {

I am surprised that the compiler points the line of the fold as the one creating the error.
If, however, I make the bounds explicit with forSome , as a result I cannot pass to the constructor of my class multiple collections:SingleTermStructureArbitrageableCollection[R,T,K] with different R and T

Can you explain me what the problem is?
Best RegardsEdmondo
H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: Existential types

please provide something that "compiles" so i can solve this riddle.

-------- Original-Nachricht --------
> Datum: Tue, 31 Jan 2012 15:47:33 +0100
> Von: Edmondo Porcu
> An: scala-user
> Betreff: [scala-user] Existential types

> Dear all,
>
> I have an issue with existential types I can't solve.
>
> abstract class CurveTermStructureExtractionInput[T <: TermStructure](
> val collections:SingleTermStructureArbitrageableCollection[_,T,_] *) {
>
> collections.foldLeft(0){ case (item,coll) =>item+coll.size}
>
> }
>
>
> error: type arguments [_$1,T,_$2] do not conform to trait
> SingleTermStructureArbitrageableCollection's type parameter bounds [T <:
> com.gottex.gottware.common.datamodels.finance.securities.impl.SecurityImpl,X
> <:
> com.gottex.gottware.common.datamodels.finance.math.termstructure.representation.TermStructure,+Repr
> <:
> com.gottex.gottware.common.datamodels.finance.collections.specialized.termstructures.SingleTermStructureArbitrageableCollection[T,X,Repr]]
> collections.foldLeft(position) {
>
>
> I am surprised that the compiler points the line of the fold as the one
> creating the error.
>
> If, however, I make the bounds explicit with forSome , as a result I
> cannot
> pass to the constructor of my class
> multiple collections:SingleTermStructureArbitrageableCollection[R,T,K]
> with
> different R and T
>
>
> Can you explain me what the problem is?
>
> Best Regards
> Edmondo

edmondo1984
Joined: 2011-09-14,
User offline. Last seen 28 weeks 3 days ago.
Re: Existential types
Dear Dennis, here we are...
trait MyTrait
trait MyGeneric[A<:AnyVal, T<:MyTrait,B<:String] {  val size:Int}
abstract class CurveTermStructureExtractionInput[T <: MyTrait](   val collections:MyGeneric[_,T,_] *) {
  collections.foldLeft(0){ case (item,coll) =>item+coll.size}
}
Best RegardsEdmondo
2012/1/31 Dennis Haupt <h-star@gmx.de>
please provide something that "compiles" so i can solve this riddle.

-------- Original-Nachricht --------
> Datum: Tue, 31 Jan 2012 15:47:33 +0100
> Von: Edmondo Porcu <edmondo.porcu@gmail.com>
> An: scala-user <scala-user@googlegroups.com>
> Betreff: [scala-user] Existential types

> Dear all,
>
> I have an issue with existential types I can't solve.
>
> abstract class CurveTermStructureExtractionInput[T <: TermStructure](
>   val collections:SingleTermStructureArbitrageableCollection[_,T,_] *) {
>
> collections.foldLeft(0){ case (item,coll) =>item+coll.size}
>
> }
>
>
> error: type arguments [_$1,T,_$2] do not conform to trait
> SingleTermStructureArbitrageableCollection's type parameter bounds [T <:
> com.gottex.gottware.common.datamodels.finance.securities.impl.SecurityImpl,X
> <:
> com.gottex.gottware.common.datamodels.finance.math.termstructure.representation.TermStructure,+Repr
> <:
> com.gottex.gottware.common.datamodels.finance.collections.specialized.termstructures.SingleTermStructureArbitrageableCollection[T,X,Repr]]
> collections.foldLeft(position) {
>
>
> I am surprised that the compiler points the line of the fold as the one
> creating the error.
>
> If, however, I make the bounds explicit with forSome , as a result I
> cannot
> pass to the constructor of my class
> multiple collections:SingleTermStructureArbitrageableCollection[R,T,K]
> with
> different R and T
>
>
> Can you explain me what the problem is?
>
> Best Regards
> Edmondo

H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: Existential types

here you go:
trait MyTrait

trait MyGeneric[A <: AnyVal, T <: MyTrait, B <: String] {
val size: Int
}

abstract class CurveTermStructureExtractionInput[T <: MyTrait](val
collections: MyGeneric[_ <: AnyVal, T, _ <: String]*) {

collections.foldLeft(0) {case (item, coll) => item + coll.size}

}

_ means: anything goes here (to be more specific: "Any")
since the type parameter must extend Anyval, _ is too general. it must
be _ <: AnyVal
same for _ <: String

i do not know why the compiler does not figure that out on its own.

Am 31.01.2012 19:14, schrieb Edmondo Porcu:
> trait MyTrait
>
> trait MyGeneric[A<:AnyVal, T<:MyTrait,B<:String] {
> val size:Int
> }
>
> abstract class CurveTermStructureExtractionInput[T <: MyTrait](
> val collections:MyGeneric[_,T,_] *) {
>
> collections.foldLeft(0){ case (item,coll) =>item+coll.size}
>
> }
>

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