Created
June 11, 2019 13:19
-
-
Save mpilquist/79c6a12313a53b44fcad8883765bc426 to your computer and use it in GitHub Desktop.
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
| package leopards { | |
| trait Functor[F[_]] { | |
| def (fa: F[A]) map[A, B](f: A => B): F[B] | |
| def (fa: F[A]) void[A]: F[Unit] = fa.map(_ => ()) | |
| } | |
| delegate for Functor[List] { | |
| def (fa: List[A]) map[A, B](f: A => B): List[B] = | |
| fa.map(f) | |
| } | |
| delegate [T] for Functor[[X] =>> T => X] { | |
| def (fa: T => A) map[A, B](f: A => B): T => B = | |
| fa.andThen(f) | |
| } | |
| } | |
| package usage { | |
| import delegate leopards._ | |
| val ex1 = List(1, 2, 3).void | |
| } | |
| /* | |
| -- [E007] Type Mismatch Error: prio.scala:21:16 -------------------------------- | |
| 21 | val ex1 = List(1, 2, 3).void | |
| | ^^^^^^^^^^^^^ | |
| |Found: List[Int] | |
| |Required: ?{ void: ? } | |
| |Note that implicit extension methods cannot be applied because they are ambiguous; | |
| |both object Functor_List_instance in package leopards and method Functor_Function_instance in package leopards provide an extension method `void` on List[Int] | |
| one error found | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment