Skip to content

Inconsistencies in syntax when defining instances #6

@Adowrath

Description

@Adowrath

I noticed, while reading part 3, "Instance Declarations", that you used two different syntaxes:
You start out with a :.

extension intAdditionSemigroup : new Semigroup[Int] {
  def combine(this x: Int)(y: Int) = x + y
}

But later on change that to a normal =:

  extension fooEq[A: Eq] = new Eq[Foo[A]] {
    def eqv(this x: Foo[A])(y: Foo[A]): Boolean =
      x.a.eqv(y.a)
  }

Further on, in part 4, you lose extension as a keyword and go back to implicit vals again. Same situation in the last part.

Which of the two do you intend?


Also, slight correction in the "Using default implementations" section:

extension readerApplicativeFunctor[R] :
  new Applicative[[A] => Reader[R, A]] with Functor[A] => Reader[R, A]] {
    def pure[A](a: A): Reader[R, A] =
      Reader(_ => a)

    def ap[A, B](this fa: Reader[R, A])(ff: Reader[R, A => B]): Reader[R, B] =
      Reader(r => ff.run(r)(fa.run(r)))
  }

Just syntactically, your Functor is missing a [ in there, but I don't think that you wrap square brackets around the types in kind-projector (correct me if I'm wrong, I've never used it).

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