Skip to content

Instantly share code, notes, and snippets.

@Khalian
Last active February 21, 2020 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Khalian/c11012655439e4903d21fb0eb5797d29 to your computer and use it in GitHub Desktop.
Save Khalian/c11012655439e4903d21fb0eb5797d29 to your computer and use it in GitHub Desktop.
TypeHierarchy.scala
// A classic definition of functor, applicative and monad.
trait Functor[T[_]] {
def apply[A](a: A): T[A]
def map[A, B](f: A => B)(a: T[A]): T[B]
}
trait Applicative[T[_]] extends Functor[T[_]] {
def pmap[A, B](f: T[A => B])(a : T[A]) : T[B]
}
trait Monad[T[_]] extends Functor[T[_]] {
def flatMap[A, B](f: A => T[B])(a: T[A]) : T[B]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment