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

Consistency tests for override instances #1684

Open
yilinwei opened this issue May 19, 2017 · 3 comments
Open

Consistency tests for override instances #1684

yilinwei opened this issue May 19, 2017 · 3 comments

Comments

@yilinwei
Copy link
Contributor

Currently we have overrides for specific methods for instances which are more efficient.

It's important that the output of the overriden method should be consistent with the output of the derived method and should be tested.

@kailuowang
Copy link
Contributor

kailuowang commented May 19, 2017

The strategy we had in the past is to add it to the laws, example. The issue with this strategy is that these tests are not the same as the more fundamental laws that usually test against abstract methods. Shall we setup a new organization to make a distinction between these two types of laws?

@peterneyens
Copy link
Collaborator

peterneyens commented May 19, 2017

FWIW, this is what I played around with after we talked about creating some sort of benchmark for overridden/default implementations (see #1532 (comment)).

In essence it boils down to a type class specific wrapper that implements only the fundamental type class operations using the actual instance of the data type it wraps.

case class FoldableWrapper[F[_], A](val inner: F[A])(implicit F: Foldable[F])

object FoldableWrapper {
  implicit def foldableWrapperInstance[F[_]](implicit F: Foldable[F]): Foldable[FoldableWrapper[F, ?]] =
    new Foldable[FoldableWrapper[F, ?]] {
      def foldLeft[A, B](fa: FoldableWrapper[F, A], b: B)(f: (B, A) => B): B =
        F.foldLeft(fa.inner, b)(f)
    
      def foldRight[A, B](fa: FoldableWrapper[F, A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] =
        F.foldRight(fa.inner, lb)(f)
    } 
}

Maybe we can use something like this somehow (for consistency and/or benchmarking) ?

@yilinwei
Copy link
Contributor Author

yilinwei commented May 19, 2017

@peterneyens I like that approach and I think we can/should generate these tests.

On a side note it's like the issue described in #1659, in that we have a behaviour we expect but we enforce it via manual checking rather than in some automated fashion.

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

3 participants