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