Skip to content

Instantly share code, notes, and snippets.

@purefn
Created November 14, 2011 16:30
Show Gist options
  • Save purefn/1364358 to your computer and use it in GitHub Desktop.
Save purefn/1364358 to your computer and use it in GitHub Desktop.
trait Pointed[F[_]] {
def point[A](a: => A): F[A]
}
trait Functor[F[_]] {
def fmap[A, B](fa: F[A])(f: A => B): F[B]
}
trait Show[A] {
def shows(a: => A): String
}
trait OptionPointedInstances {
implicit def optionPoint: Pointed[Option] = new Pointed[Option] {
def point[A](a: => A) = Some(a)
}
}
trait OptionShowInstances extends OptionPointedInstances {
implicit def optionShow[A]: Show[Option[A]] = new Show[Option[A]] {
def shows(a: => Option[A]) = a.toString
}
}
trait OptionFunctorInstances extends OptionPointedInstances {
implicit def optionFunctor: Functor[Option] = new Functor[Option] {
def fmap[A, B](fa: Option[A])(f: A => B) = fa map f
}
}
object optionShowInstances extends OptionShowInstances
object optionFunctorInstances extends OptionFunctorInstances
object test {
import optionShowInstances._
import optionFunctorInstances._
def point[F[_], A](a: => A)(implicit F: Pointed[F]) = F.point(a)
point[Option, Int](1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment