Closed rklaehn closed 8 years ago
Eq
and Hash
are lawful and useful to algebraic code. I wish scala had a Show typeclass, but I'd tend say we should not have it here. You have a barrier against the slippery slope: adding only typeclasses implied by Object, but still I'm weakly opposed.
Next, other than style, I'm not sure what is that bad about .toString. I mean, I would not design a new language with .toString on everything, but given that Java and scala already did that, I'm not sure the win of having Show other style purity.
I see your point of view.
About why having Show: often implementing toString requires access to typeclass instances. So you have to capture the typeclass instances into your data structures in order to implement toString, which is inefficient, and also drives you to a more OO design.
Yeah - a good point. I don't think toString
is too bad, but an example in Spire is that we often have to use this really nasty hack to work with generic values when we don't have a type class available to help us. This shows up more when implementing equals
and many of the ScalaNumber
methods :\
That said, I'd rather not have Show
here as well.
This might be a bit controversial, since Show is not really "algebraic". But I think that algebra-core has the potential to become something like the predef for people working with typeclasses.
I would like to have a typeclass-based alternative to everything in java.lang.Object in algebra-core. Eq already exists. There is issue #38 for adding a simple hashing typeclass. So that leaves Show.
There is a Show in cats: https://github.com/non/cats/blob/master/core/src/main/scala/cats/Show.scala . Maybe just move that one level up?