typelevel / algebra

Experimental project to lay out basic algebra type classes
https://typelevel.org/algebra/
Other
378 stars 69 forks source link

Add Unit instances #87

Closed ceedubs closed 8 years ago

ceedubs commented 8 years ago

Mostly I wanted the Order instance for Unit. The use-case is that in some tests we want to check if something two instances of Error Xor Unit are equal, and the derived Eq instance for Xor needs an Eq instance for both sides.

I have no idea whether the CommutativeRig[Unit] is a good idea or is useful. It seems to be law-abiding though. Let me know if you want me to rip it out.

non commented 8 years ago

I'm pretty sure you can upgrade it to a CommutativeRing[Unit] with no problems (it is a zero ring: https://en.wikipedia.org/wiki/Zero_ring). There's little harm in having these instances, even if they are mostly just a novelty.

johnynek commented 8 years ago

+1 to Ring. Also I think you get Lattice here.

johnynek commented 8 years ago

actually, BoundedSemilattice is what we I should have said instead of Lattice.

ceedubs commented 8 years ago

@non @johnynek thanks for the fast feedback and suggestions. I've made the unit algebra extend CommutativeRing and BoundedSemilattice.

Am I doing the right law-checking? It's straightforward for order and boundedSemilattice, but I wasn't sure what to do for CommutativeRing. I didn't spot a def commutativeRing in RingLaws that would have been the obvious answer.

ceedubs commented 8 years ago

Also thanks for the link @non. That was helpful.

non commented 8 years ago

:+1:

tixxit commented 8 years ago

I don't think we should be able to get anything beyond Rng here. I think a Ring implies that 1 and 0 are different. OTOH, the laws seem to pass...

tixxit commented 8 years ago

Ah - nevermind - this ring is the only ring where 1 != 0! Carry on :)