Skip to content

Instantly share code, notes, and snippets.

@gigiigig
Last active August 29, 2015 14:25
Show Gist options
  • Save gigiigig/66b4a872fe49257593ae to your computer and use it in GitHub Desktop.
Save gigiigig/66b4a872fe49257593ae to your computer and use it in GitHub Desktop.
Type Refinements
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