Applicative instances for homogeneous tuples
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
Hey, I think there are no instances of Functor/Applicative for tuples other than pairs (https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/instances/tuple.scala#L29).
Example:
object XX {
import cats.syntax.all._
type HomoTuple4[T] = (T, T, T, T)
implicit val t4ap: Applicative[HomoTuple4] = new Applicative[HomoTuple4] {
override def pure[A](x: A): (A, A, A, A) = (x, x, x, x)
override def ap[A, B](ff: (A => B, A => B, A => B, A => B))(fa: (A, A, A, A)): (B, B, B, B) =
(ff._1(fa._1), ff._2(fa._2), ff._3(fa._3), ff._4(fa._4))
}
((1, 2, 3, 4): HomoTuple4[Int]).map(_.toLong)
}
There is one significant problem that I see: scalac is not able to infer proper type without explicit type annotation. Do you see any way to fix that? Without it those instances are not very useful.
If there is a way to fix the above and if you could confirm that there is no other obvious problems with it and that such instances are desired then I will be happy to make a PR. And if so I could also use a tip or two on where to put those instances (I have very little experience with managing bin compat).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review core/src/main/scala/cats/instances/tuple.scala around line 29 and the homogeneous-tuple example in the issue. First investigate Scala compiler type inference for higher-arity tuples, then check the project’s binary-compatibility guidance; done means determining whether useful Functor/Applicative instances can be added without requiring problematic annotations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100