Skip to content
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

Rethinking cats.data.Prod #874

Closed
adelbertc opened this issue Feb 11, 2016 · 6 comments
Closed

Rethinking cats.data.Prod #874

adelbertc opened this issue Feb 11, 2016 · 6 comments

Comments

@adelbertc
Copy link
Contributor

For product composition of type classes we are using cats.data.Prod which is defined like

sealed trait Prod[F[_], G[_], A]

which fixes F and G to be unary type constructors. This works fine when defining product composition for type classes abstracting over unary type constructors like Functor and Apply. But for type classes like Bifunctor and Bifoldable which abstract over binary type constructors, they also have product composition but they can't use cats.data.Prod. We can just have the compose on those type classes return the tuple directly Lambda[(A, B) => (F[A, B], G[A, B])], but that would be inconsistent with our use of Prod in the other type classes.

I looked in the Essence of the Iterator Pattern paper which I believe inspired cats.data.Prod and dont' see them using it with the Bifoldable-y stuff.

/cc @eed3si9n since he added Prod

@adelbertc
Copy link
Contributor Author

Another argument for using the tuple directly and putting it on the type class e.g. Apply#product would be the compose and product composition combinators would be in the same place instead of compose being on the type class and product being on Prod.

@eed3si9n
Copy link
Contributor

I preferred defining Prod[F[_], G[_], A] since it's more restrictive than (A, B). Prod specifically stores (F[A], G[A]) whereas a Tuple2 can store whatever.
Another motivation was to define typeclass instances for Functor and Applicative unambiguously. Tuple2 as a datatype can overload all sorts of semantics like a pair and coproduct/HList, where they have their own definition of what map means in there. G[F[A]] on the other hand, is pretty clear what it means.

@adelbertc
Copy link
Contributor Author

You can still get an (A, B) if you have F = G = Id where type Id[A] = A. But good point about the Tuple2 overloads.. should we then have a BiProd[F[_, _], G[_, _], A, B] for the Bi- type classes?

@eed3si9n
Copy link
Contributor

should we then have a BiProd[F[_, _], G[_, _], A, B] for the Bi- type classes?

To me that makes sense.

@adelbertc
Copy link
Contributor Author

I'll take on adding BiProd, will use as example for my talk at http://typelevel.org/event/2016-03-summit-philadelphia/

adelbertc added a commit to adelbertc/cats that referenced this issue Mar 2, 2016
@adelbertc
Copy link
Contributor Author

Closing in favor of #968

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants