Last active
August 29, 2015 14:25
-
-
Save gigiigig/66b4a872fe49257593ae to your computer and use it in GitHub Desktop.
Type Refinements
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
import scalaz._ | |
import Scalaz._ | |
object console extends App { | |
trait Apart[F] { | |
type T | |
type G[X] | |
def apply(f: F): G[T] | |
} | |
object Apart { | |
type Aux[FA, A, F[_]] = Apart[FA] { type T = A; type G[X] = F[X] } | |
implicit def af[F[_], A]: Apart[F[A]] = new Apart[F[A]] { | |
type T = A | |
type G[X] = F[X] | |
def apply(f: F[A]): G[T] = f | |
} | |
} | |
def foo[This, Mo, F[_]](ft: This) | |
(implicit apart: Apart.Aux[This, Mo, F], | |
F: Functor[F], | |
Mo: Monoid[Mo]) = { | |
F.map(apart(ft))(_ => Mo.zero) | |
} | |
foo(some(3)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment