-
-
Save suhailshergill/10907771 to your computer and use it in GitHub Desktop.
scala: monad implies functor
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 Monad[M[_]] { | |
implicit def `Monad ~> Functor`[M[_]: Monad]: Functor[M] = new Functor[M]{} | |
} | |
trait Functor[F[_]] { | |
} | |
object Functor { | |
implicit val OptionFunctor: Functor[Option] = new Functor[Option]{} | |
} | |
case class Foo[A]() | |
object Foo extends Monad[Foo] { | |
implicit val M: Monad[Foo] = new Monad[Foo]{} | |
} | |
def requiresFunctor[F[_]: Functor, A](f: F[A]) = 42 | |
requiresFunctor(Foo[Int]()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment