[spire] [algebra] [cats] Why typeclasses Eq / PartialOrder / Order are not declared as contravariant

53 views
Skip to first unread message

Tongfei Chen

unread,
May 28, 2016, 1:23:41 PM5/28/16
to Typelevel Users & Development List
Why don't we do things like these?
trait Eq[-A]
trait
PartialOrder[-A]
trait
Order[-A]

I'd like to know the rationale behind the decision of making them invariant. Thanks!

Ben Hutchison

unread,
May 28, 2016, 11:29:18 PM5/28/16
to Tongfei Chen, Typelevel Users & Development List

--
You received this message because you are subscribed to the Google Groups "Typelevel Users & Development List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to typelevel+...@googlegroups.com.
To post to this group, send email to type...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/typelevel/3c695808-8e99-4ec4-a3d9-a2634b9060cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Miles Sabin

unread,
May 29, 2016, 3:59:59 AM5/29/16
to Ben Hutchison, Tongfei Chen, Typelevel Users & Development List

Ben Hutchison

unread,
May 29, 2016, 8:13:15 AM5/29/16
to Miles Sabin, Tongfei Chen, Typelevel Users & Development List
Nice! The dotty commit [https://github.com/lampepfl/dotty/commit/89540268e] implies that Martin's no longer holds the objections raised in the 2012 thread [https://groups.google.com/forum/#!topic/scala-language/ZE83TvSWpT4], thats encouraging progress.

For me a fix would be all upside, but possibly there are existing codebases that, perhaps unwittingly, rely on the current behavior and break when its fixed. 

It seems like implementing the fix isn't a major obstacle, but will there be a willingness to evolve the language when there's a chance of collateral damage? 

-Ben

Matthew Pocock

unread,
May 29, 2016, 8:26:23 AM5/29/16
to Ben Hutchison, type...@googlegroups.com, Tongfei Chen, Miles Sabin

Just saying that if they are invariant, you can always recover contravariance by deriving [B <:< A] Eq [A] => Eq [B]. I've sometimes found this manual control of narrowing and widening to be easier to control.

Tongfei Chen

unread,
May 29, 2016, 8:57:28 PM5/29/16
to Typelevel Users & Development List, brhut...@gmail.com, cton...@gmail.com
Great!
Reply all
Reply to author
Forward
0 new messages