Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch in typeclass definition #83

Open
dszakallas opened this issue Jun 24, 2017 · 0 comments
Open

Type mismatch in typeclass definition #83

dszakallas opened this issue Jun 24, 2017 · 0 comments

Comments

@dszakallas
Copy link

dszakallas commented Jun 24, 2017

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 dszakallas changed the title Type mismatch in typeclass definition using simulacrum Type mismatch in typeclass definition Jun 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant