Hello,
-- I have the following error: inferred type arguments [HypeParamSearchV2.Parameter,Int,Int] do not conform to method apply's type parameter bounds [P[_] <: HypeParamSearchV2.Parameter[T],T,U] [error] val pr1 = ParameterRange( p1, 0, 10, 1 ) I have looked around and seen that some people solve this with existential types or type parameters. However, I cannot wrap my mind around those "examples". To explain, I have the following two entities: trait Parameter[ T ] { type Self <: Parameter[ T ] def apply( v: T ): Self } and import scala.language.higherKinds case class ParameterRange[ P[_] <: Parameter[T], T, U ]( val param: P[T], val start: T, val stop: T, val config: U ) { def toStream( f: (T, T, U ) => Stream[T] ): Stream[ P[T]#Self ] = { val st = f( start, stop, config ) val r = st.map{ x : T => param( x ) } r } To test this I do: class ModelA { case class Param1[T]( v: T ) extends Parameter[ T ] { type Self = Param1[Int]; def apply( v: Int ) = new Param1( v ) } val p1 : Parameter[Int]= Param1(0) val pr1 = ParameterRange( p1, 0, 10, 1 ) } More specifically I have: type mismatch; [error] found : HypeParamSearchV2.Parameter[Int] [error] required: P[T] [error] val pr1 = ParameterRange( p1, 0, 10, 1 ) Why is P[T] not equal to Parameter[Int]? How can I circumvent this problem? I have tried "massaging" the types but not success. Maybe the basic design is faulty? Any help is appreciated. TIA, Hugo You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Hello,
-- Please ignore this unless you have the same issue or are interested in this. Apologies for the noise. (Why does this happen so often? After hours on end trying this and that I find the answer after posting the question (was on this list).) Anyway here is the solution: Change : case class ParameterRange[ P[_] <: Parameter[T], T, U ]( to class ParameterRange[ P[X] <: Parameter[X], T, U ]( which leads me to another questions. Why don't we have to declare X? TIA HF On Tuesday, 31 January 2017 13:47:24 UTC, Hugo Ferreira wrote:
You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
On 1/31/17 9:04 AM, Hugo Ferreira
wrote:
P[X] <: Parameter[X] means P: * -> *, such that for all X: *, P[X] <: Parameter[X]. So there is no specific X to talk about; you are making a claim that is quantified over X, so the variable X is bound by the expression P[X] itself. So it is declared! :) Your old variant meant P: * -> * such that for all E: *, P[E] <: Parameter[T] (where T is the later type parameter). (This is a restatement of the actual bound, (P[E] forSome {type E}) <: Parameter[T].) This was a claim about a specific T, bound outside the expression. Note specifically that Parameter's type parameter and P's type parameter are not related at all. Given trait Disconnect[A] extends Parameter[Int] Under your original declaration, ParameterRange[Disconnect, Int, Int] is well-kinded, and in the body of ParameterRange, P[String] <: Parameter[T]; I imagine neither of these behaviors seem correct to you, and both are corrected by your new form. The original error was probably that Parameter itself did not conform to the bounds declared for P, and there was no way to infer T. It's not common to declare X when not writing a bound, because these bounds are relatively rare, and so it's just extra noise when all you're trying to do is declare a higher-kinded type. I also imagine 99% of folks saw the _ form as their first n examples of HKTs, for some large n, and copied the style. -- Stephen Compall -- You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble - Scala Resume Examples | Edit this page |