-
Hi, Tuples in cats inherit all type class implementations from its "rightmost" type, e.g. Welcome to the Ammonite Repl 2.5.0 (Scala 2.13.7 Java 11.0.11)
…
@ (true, 1).map(_ + 1)
res2: (Boolean, Int) = (true, 2) Could someone elaborate on this design choice? Isn't it a bit weird?
Would it be better to define type class instances like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Just to clarify your question. Tuples are heterogeneous by their nature. So what would you expect to get as a result in the case below:
? |
Beta Was this translation helpful? Give feedback.
-
There are two questions here:
I think there is an argument that the instances are too confusing and should not be in default scope. I am somewhat sympathetic to the idea that perhaps these should require an import. On to the second question: if you are going to have an instance in scope, why is it the right most? The answer there, I believe has to do with scala's type inference with higher kinded types. I think eventually a right to left inference algorithm for higher kinded types, was fixed (I believe became default in 2.12 or 2.13). See this old bug for more information: scala/bug#2712 |
Beta Was this translation helpful? Give feedback.
There are two questions here:
I think there is an argument that the instances are too confusing and should not be in default scope. I am somewhat sympathetic to the idea that perhaps these should require an import.
On to the second question: if you are going to have an instance in scope, why is it the right most? The answer there, I believe has to do with scala's type inference with higher kinded types. I think eventually a right to left inference algorithm for higher kinded types, was fixed (I believe became default in 2.12 or 2.13). See this old bug for more i…