Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Add Signed and TruncatedDivision typeclasses #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

denisrosset
Copy link
Contributor

This follows the Spire implementations as well (we just put Sign into the Signed companion object).

We added the missing companion object functions.

Copy link
Contributor

@johnynek johnynek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool. Thanks for sending.


def *(that: Sign): Sign = Sign(this.toInt * that.toInt)

def **(that: Int): Sign = this match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment that this is exponentiation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

def signed(implicit A: Signed[A]) = new OrderProperties(
name = "signed",
parent = Some(order),
"abs non-negative" -> forAll((x: A) => A.sign(A.abs(x)) != Signed.Negative),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we require that abs(x) >= x?

Seems natural to me, but I don't see that is implied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

@@ -123,6 +123,8 @@ class LawTests extends munit.DisciplineSuite {
checkAll("Long", RingLaws[Long].commutativeRing)
checkAll("Long", LatticeLaws[Long].boundedDistributiveLattice)

// catsKernelStdOrderForBigInt
checkAll("BigInt", OrderLaws[BigInt].truncatedDivision)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add implementations for the specialized things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for the intermediate ring structures-- the instances are only approximations due to the type limited range.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants