scalaz-plugin icon indicating copy to clipboard operation
scalaz-plugin copied to clipboard

Rewriting

Open sir-wabbit opened this issue 7 years ago • 1 comments

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.

sir-wabbit avatar Jun 28 '18 20:06 sir-wabbit

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

sir-wabbit avatar Jun 29 '18 09:06 sir-wabbit