Skip to content

Override polymorphic methods #3

@carymrobbins

Description

@carymrobbins

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions