Last active
June 23, 2020 08:39
-
-
Save milessabin/f3c6f48276b0a6cf7875eee3060d11af to your computer and use it in GitHub Desktop.
Constraining trait type parameters via a super class type parameter constraint ... different instances along different paths
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