Reputation: 170919
Shapeless allows type-specific cases in polymorphic functions. Is there some way to achieve the same with a type member, and get the moral equivalent of
type Foo[T] = T match {
case Int => ...
case List[A] => ...
}
?
Upvotes: 3
Views: 133
Reputation: 17431
Depending on your use case you can emulate a type-level function by providing implicits for the cases (this is how a lot of shapeless works):
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 = ...
Upvotes: 1
Reputation: 23056
No.
No, there really isn't. Really. No. ... is that 30 characters yet?
Upvotes: 5