scalaz-plugin
scalaz-plugin copied to clipboard
Rewriting
Possible syntax:
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
object Functor {
def fusion[F[_], A, B, C](fa: F[A], f: A => B, g: B => C)
(implicit F: Functor[F], R: Rewrites): Rewrite =
F.map(F.map(fa)(f))(g) rewriteTo F.map(fa)(f andThen g)
}
///////////////////////////////////
///////////////////////////////////
class rewrite extends annotation.StaticAnnotation
final class Rewrite private()
final class Rewrites private ()
implicit class RewriteSyntax[A](val from: A) {
def rewriteTo(to: A)(implicit R: Rewrites): Rewrite = ???
}
R : Rewrites is there to guarantee that fusion won't be called by the user.
For inspiration:
https://github.com/paulp/fusion/commit/3afd0ca8c3e3d7b198df3568791bfca5372f3e78 https://github.com/nativelibs4java/Scalaxy https://github.com/nativelibs4java/scalaxy-streams https://github.com/nativelibs4java/Scalaxy/tree/master/Obsolete/Compilets https://github.com/tommie/scala-rangefor/blob/master/src/RangeFor.scala