Last active
June 23, 2020 08:40
-
-
Save milessabin/e7744cca709b95035d9f928800d5f276 to your computer and use it in GitHub Desktop.
Constraining a trait type parameter via a super class type parameter constraint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.{Applicative, Monad} | |
import cats.implicits._ | |
abstract class Foo[+M[_[_]], F[_]](implicit val M: M[F]) | |
trait Bar[F[_]] extends Foo[Applicative, F] { def bar = Applicative[F] } | |
trait Baz[F[_]] extends Foo[Monad, F] { def baz = Monad[F] } | |
class User[F[_]: Monad] extends Bar[F] with Baz[F] | |
object Test { | |
val u = new User[List] | |
u.bar: Applicative[List] | |
u.baz: Monad[List] | |
} | |
// scala> val u = new User[List] | |
// val u: constrain.User[List] = constrain.User@5a70669f | |
// | |
// scala> u.bar | |
// val res0: cats.Applicative[List] = cats.instances.ListInstances$$anon$1@577b462b | |
// | |
// scala> u.baz | |
// val res1: cats.Monad[List] = cats.instances.ListInstances$$anon$1@577b462b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment