Expressing type inequality conditions in a simple estimate

import shapeless._

trait Something[T <: Something[T, R], R] {}
class Test[T <: Something[T, R], R, T1 <: Something[T1, _] <:!< T](t: T, t1: T1) {}

      

but i get:

type arguments [T1,?] do not conform to trait Something type parameter bounds [T <: Something[T,R],R]

      

Which makes sense, except that I expect this to work:

class Test1[T <: Something[T, R], R, T1 <: Something[T1, R1] <:!< T, R1](t: T, t1: T1)

      

But it asks for the same grade on T1 <: Something[T, R]

.

My point is that this class takes 4 type arguments, each pair describes a different descendant Something[T <: Something[T, R], R]

. Simple put, forced to T != T1

.

What is the correct way to do this?

+3


source to share


1 answer


General example

import shapeless._
class Foo[A, B](a: A, b: B)(implicit ev: A =:!= B)
val x = new Foo(1, "hello")
// x: Foo[Int,String] = Foo@4015d0b9

val y = new Foo(1, 2)
// error: ambiguous implicit values:
// both method neqAmbig1 in package shapeless of type [A]=> shapeless.=:!=[A,A]
// and method neqAmbig2 in package shapeless of type [A]=> shapeless.=:!=[A,A]
// match expected type shapeless.=:!=[Int,Int]
//              new Foo(1, 2)
//              ^

      



in your specific case

class Test[A, B, T <: Something[T, A], T1 <: Something[T1, B]](t: T, t1: T1)(implicit ev: T =:!= T1)

      

+3


source







All Articles