simulacrum icon indicating copy to clipboard operation
simulacrum copied to clipboard

Type mismatch in typeclass definition

Open dszakallas opened this issue 7 years ago • 0 comments

I have a hard time defining the following typeclass:

@typeclass trait ElementIterator[It[_]] {
  def record[Item[Element], Element <: ElementT, Ctx >: Context[ElementT]]
  (iterator: It[Item[Element]],
   name: String,
   what: RefExpr[Ctx, Any])
  (implicit ctxLike: ContextLike[Item],
   withVariables: WithVariables[Item[Element]]
  ): It[Item[Element]]
}

I get the following error:

Error:(11, 4) type mismatch;
  found   : sre.task.Core.WithVariables[Item[A]]
  required: sre.task.Core.WithVariables[Item[Element]]
  Note: implicit value elementIteratorForIterator is not applicable here because it comes after the application point and it lacks an explicit result type
  @typeclass trait ElementIterator[It[_]] {

I am not sure what happens here. It seems to me when Element is used in the implicit parameter list it will be freshly assigned to a new type variable A instead of matching it with the one in iterators type.

What I really want is to have is a WithVariables with the same type parameter as It.

What is really happening here? Is this a bug?

I originally asked for help on SO and a @Jasper-M suggested me as a workaround to add the @noop annotation to the method, which works.

I don't know if it should go in a separate issue, but I have another method originally in the type class with what seems to be an eligible type for generating an Op, however it is not done. So having this method:

@typeclass trait ElementIterator[It[_]] {
  def check[Item[_], Element <: ElementT, Ctx >: Context[ElementT]]
  (iterator: It[Item[Element]])
  (assert: AssertExpr[Ctx])
  (implicit ctxLike: ContextLike[Item]): It[Item[Element]]

This compiles:

import sre.task.Iterators._
ElementIterator[Iterator].check(vertices)(Eq(This.Property("name"), Const("Cat")))

However this not:

import sre.task.Iterators.ElementIterator.ops._
vertices.check(Eq(This.Property("name"), Const("Cat")))

dszakallas avatar Jun 24 '17 09:06 dszakallas