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

Create some kind of Equalable trait #46

Closed
dkettlestrings opened this issue Jan 14, 2017 · 2 comments
Closed

Create some kind of Equalable trait #46

dkettlestrings opened this issue Jan 14, 2017 · 2 comments

Comments

@dkettlestrings
Copy link
Owner

Due to the JVM's insistence that everything has an equals method that

  1. Is invoked by many standard operations (especially standard collections)
  2. Has a signature that requires it handle Any

we have ugly code. Take for example this snippet from Polynomial:

override def equals(obj: scala.Any): Boolean = {

    Try(obj.asInstanceOf[Polynomial[A]]) match {
      case Success(poly) => this.param == poly.param && trimLeadingZeros(this.coefficients) == trimLeadingZeros(poly.coefficients)
      case Failure(throwable) => false
    }
  }

The asInstanceOf guard is ugly and gets repeated anywhere I want to have a specific notion of equality. As of the writing of this issue, it appears in

  1. Polynomial
  2. ResidueClass
  3. RationalExpression

Create a trait that handles the type guard and allows the user to simply write the actual equality logic on the appropriate type.

@dkettlestrings
Copy link
Owner Author

This turns out to be much harder than I thought. In fact, Martin Odersky is proposing such a thing for Dotty. I'll just have to leave this open and see what happens. I'm concerned with moving to Dotty as most people aren't using it (I think).

@dkettlestrings
Copy link
Owner Author

Easier than I thought. Pushing a change now.

dkettlestrings added a commit that referenced this issue Sep 4, 2017
Closes #46 and removes EquivalenceClass and EquivalenceRelation
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