-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Introduce The Inverse Type #4345
base: main
Are you sure you want to change the base?
Conversation
The type `Inverse[A]` is a newtype which exists to invert the `Order`, `PartialOrder`, `UpperBounded` and `LowerBounded` instances for some type `A`. It's basically just `Id[A]` with specialized instances for ordering. Prior art: https://hackage.haskell.org/package/base-4.6.0.1/docs/Data-Ord.html#Down
I've also considered defining it on |
Currently we have a bunch of similar newtypes living in monoids. |
🤔 hmm...I don't think |
cc @typelevel/monoids |
override def hash(x: Inverse[A]): Int = | ||
Hash[A].hash(x.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like Hash[Inverse[A]].hash <==> Hash[A].hash
so what is the point of having an Inverse
for Hash
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't if you know you're dealing with an Inverse
. This is provided to solve constraints in a generic context, e.g. def foo[A: Hash]
I want to be able to call that with A
and Inverse[A]
for all A
which have a Hash
.
Introduce The Inverse Type
The type
Inverse[A]
is a newtype which exists to invert theOrder
,PartialOrder
,UpperBounded
andLowerBounded
instances for some typeA
.It's basically just
Id[A]
with specialized instances for ordering.Hypothetically, we could implement all of the instances defined for
Id
forInverse
, however before I do that (and before I write any more docs or any tests), I wanted to see what everyone thinks about this?Prior art: https://hackage.haskell.org/package/base-4.6.0.1/docs/Data-Ord.html#Down
Thoughts?