Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import scala.language.higherKinds
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
trait Traverse[F[_]] {
implicit val F: Functor[F]
}
object Traverse {
type Aux[F[_], FF] = Traverse[F] { val F: FF }
}
trait Monad[F[_]] {
implicit val F: Functor[F]
}
object Monad {
type Aux[F[_], FF] = Monad[F] { val F: FF }
}
object List {
implicit val listFunctor: Functor[List] =
new Functor[List] {
def map[A, B](fa: List[A])(f: A => B): List[B] = fa.map(f)
}
implicit val listTraverse: Traverse.Aux[List, listFunctor.type] =
new Traverse[List] {
val F: listFunctor.type = listFunctor
}
implicit val listMonad: Monad.Aux[List, listFunctor.type] =
new Monad[List] {
val F: listFunctor.type = listFunctor
}
}
object Demo {
import List._
def foo[F[_]](ff: Functor[F])(implicit M: Monad.Aux[F, ff.type], T: Traverse.Aux[F, ff.type]): F[Int] = ???
foo(listFunctor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.