Skip to content

Instantly share code, notes, and snippets.

@retronym
Forked from purefn/gist:1364358
Created November 14, 2011 17:06
Show Gist options
  • Save retronym/1364465 to your computer and use it in GitHub Desktop.
Save retronym/1364465 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._
implicitly[Pointed[Option]] // why isn't this ambiguous??
optionPoint // error: reference to optionPoint is ambiguous. As expected...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment