-
-
Save retronym/1364465 to your computer and use it in GitHub Desktop.
This file contains 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
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