Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created October 15, 2016 19:41
Show Gist options
  • Save milessabin/1ed8da29f314df2942c2dfd5f5a573e6 to your computer and use it in GitHub Desktop.
Save milessabin/1ed8da29f314df2942c2dfd5f5a573e6 to your computer and use it in GitHub Desktop.
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