simulacrum
simulacrum copied to clipboard
Hygiene problems when ops-eligible methods refer to type members of type class
Some examples:
// Fails to compile
@typeclass trait F[A] { self =>
type B = A
def f(a: A): Option[B]
}
// Fails to compile
@typeclass trait G[A] { self =>
type B = A
def f(a: A): Option[self.B]
}
// Compiles but doesn't generate an op for f
@typeclass trait H[A] { self =>
type B = A
def f(b: B): Option[A]
}
I looked at this, and it's pretty well hopeless for the same reason as #55.
// Method should only be adapted if the first parameter in the first parameter list
// matches `tparamName`
val TargetTypeName = tparamName
It's not possible to generate correct code when correctness depends on knowing how names are bound but ad hoc string matching is being used to attempt to approximate that.
Your best bet is to severely restrict how people can write their type classes so the necessary information can be obtained before typechecking.