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
Should factories like Semigroup.instance be provided for other typeclasses? #2887
Comments
Thanks for identifying these potential factory methods. I think there are value in them. On the other hand, it raises a question in my head, will such methods gives user the false impression that implementing these instances is as simple as calling these methods? Maybe a more interesting question is how do we make it obvious to users that the instances must obey the laws and there are tests they can write to ensure their lawfulness? Admittedly it's not obvious in the current setup, but will these methods make it even less so? |
As For example, would it compile to have a link to |
While
Semigroup
hascats.kernel.Semigroup#instance
,Monoid
has no equivalent, which could be implemented as:Looking at the various typeclasses in
cats.kernel
, there doesn't seem to be a pattern for which ones have factories, and which don't:Band
Semigroup.instance
BoundedSemilattice
Monoid.instance
CommutativeGroup
Group
CommutativeMonoid
Monoid.instance
CommutativeSemigroup
Semigroup.instance
Eq
Group
Group.instance(A, A => A, (A, A) => A)
might be a bit muchHash
Monoid
Monoid.instance(A, (A, A) => A)
should be easy to understandOrder
PartialOrder
Semigroup
Semilattice
Semigroup.instance
Would a PR adding these be useful?
It doesn't look like factories for the typeclasses in
cats.core
would be possible, as they'd require accepting higher-order lambdas, which I don't think can be encoded as parameters in Scala.The text was updated successfully, but these errors were encountered: