Skip to content
New issue

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

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

Already on GitHub? # to your account

Override polymorphic methods #3

Open
carymrobbins opened this issue Jul 1, 2018 · 1 comment
Open

Override polymorphic methods #3

carymrobbins opened this issue Jul 1, 2018 · 1 comment

Comments

@carymrobbins
Copy link

Ideally, given this Functor definition -

trait Functor[F[_]] {
  def map[A, B](f: A => B)(fa: F[A]): F[B]
}

We could create an instance with pascal via -

  implicit val functorOption: Functor[Option] =
    ν[Functor[Option]].map[A, B](f => fa => fa.map(f))

However, this doesn't work. We have to define Functor like this instead -

trait Functor[F[_]] {
  def map[A, B]: (A => B) => F[A] => F[B]
}

Then the instance compiles. Ideally, we should be able to define it as a polymorphic method and the rewrites should be able to handle it accordingly via an override. Maybe this becomes difficult since I believe this all happens before typer, which means we can't easily access the method signature to override. In that case, maybe there's an alternate way to represent such an override?

@TomasMikula
Copy link
Owner

From

ν[Functor[Option]].map[A, B](f => fa => fa.map(f))

not only can the plugin not tell whether the map signature is

def map[A, B](f: A => B)(fa: F[A]): F[B]

or

def map[A, B](f: A => B): F[A] => F[B]

or

def map[A, B]: (A => B) => F[A] => F[B]

but the plugin is not even able to infer parameter types and return type. For return type it is not a problem: we just omit it in the generated code:

new Functor[Option] {
  def map[A, B] = f => fa => fa.map(f)
}

But parameter types would have to be specified in the generated code.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants