Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created January 21, 2014 13:44
Show Gist options
  • Save gclaramunt/8540311 to your computer and use it in GitHub Desktop.
Save gclaramunt/8540311 to your computer and use it in GitHub Desktop.
The code is probably incorrect, but it doesn't report the line where the error happens.
import scala.language.higherKinds
object Regular1 {
trait Bifunctor[F[_, _]] {
def bimap[A, R, B, S](fa: F[A, R], f: A => B, g: R => S): F[B, S]
}
trait Regular2[T[_]]{
def from2[A,PF2[_,_]]:T[A]=>PF2[A,T[A]]
def to2[A,PF2[_,_]]:PF2[A,T[A]]=>T[A]
}
case class Comp2[A,R,F[A,R],D[F[A,R]]](unComp2:D[F])
def pmap[A,B,D[_]:Regular2,DF2D[_,_]:Bifunctor](da:D[A],f:A=>B):D[B]={
val d=implicitly[Regular2[D]]
val bf=implicitly[Bifunctor[DF2D]]
d.to2(bf.bimap(d.from2(da),f, (x:D[A])=>pmap(x,f)(d,bf)))
}
trait CompApply[D[_],F[_,_],PF2[_,_]]{
type PF2D[X]=PF2[X,D[X]]
type BF[A,R]=Comp2[A,R,F,PF2D]
}
implicit def BiComp[F[_,_]:Bifunctor,D[_]:Regular2,PF2[_,_]:Bifunctor]=new Bifunctor[CompApply[D,F,PF2]#BF]{
type PF2D[X]=CompApply[D,F,PF2]#PF2D[X]
val bf=implicitly[Bifunctor[F]]
val d=implicitly[Regular2[D]]
def bimap[A, R, B, S](fa: Comp2[A,R,F,PF2D], f: A => B, g: R => S): Comp2[B,S,F,PF2D]= Comp2(
pmap(fa.unComp2, (x:F[A,R]) => bf.bimap(x,f,g))(d,bf)
)
}
}
@gclaramunt
Copy link
Author

I get:
47. Waiting for source changes... (press enter to interrupt)
[info] Compiling 1 Scala source to /home/gabriel/code/error/target/scala-2.10/classes...
[error] type mismatch;
[error] found : this.PF2D[F]
[error](which expands to) PF2[F,D[F]]
[error] required: ?D
[error] Note that implicit conversions are not applicable because they are ambiguous:
[error] both method any2Ensuring in object Predef of type [A](x: A)Ensuring[A]
[error] and method any2ArrowAssoc in object Predef of type [A](x: A)ArrowAssoc[A]
[error] are possible conversion functions from this.PF2D[F] to ?D
[error] one error found
error Compilation failed
[error] Total time: 0 s, completed Jan 21, 2014 11:42:37 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment