Type-type in a type synonym

Shapeless allows type-specific cases in polymorphic functions. Is there a way to achieve this with a type member and get the moral equivalent

type Foo[T] = T match {
  case Int => ...
  case List[A] => ...
}

      

?

+3


source to share


2 answers


Not.



No, not really. Indeed. No ... is that 30 more characters?

+5


source


Depending on your use case, you can emulate a type level function by providing implications for the cases (so much works formless):



sealed trait Foo[T] {
  type Out
}
object Foo {
  implicit object IntFoo extends Foo[Int] {
    type Out = String
  }
  implicit def list[A] = new Foo[List[A]] {
    ...
  }
}

def myPolymorphicFunction[T](t: T)(implicit foo: Foo[T]): foo.Out = ...

      

+1


source







All Articles