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

Data structure methods #25

Closed
julien-truffaut opened this issue Feb 1, 2015 · 6 comments
Closed

Data structure methods #25

julien-truffaut opened this issue Feb 1, 2015 · 6 comments

Comments

@julien-truffaut
Copy link
Contributor

shall we implement type class methods (e.g. map, show) on data structures in cats.data or shall we get them via ops implicit classes?

@ceedubs
Copy link
Contributor

ceedubs commented Feb 2, 2015

Certain things (like show) are going to need an implementation somewhere. To me it seems to make sense to put the implementations on the data structure itself and then have the type class instance call through to it.

However, there's also the question of derived methods. At nescala @tpolecat, @non, some others (whose GitHub handles I don't know :( ), and I were discussing what options there might be to have derived methods available on data structures for free. It's always slightly annoyed me that in scalaz it's pretty ad hoc as to which derived type class methods are available on a given structure. I can't recall whether or not we came to a good solution. Maybe they remember?

@julien-truffaut
Copy link
Contributor Author

I also like defining the methods in the class because it gives a better documentation and no need of special import. however, what do we do for TC like Traverse or Fold which have a lot of derived methods?

@ceedubs
Copy link
Contributor

ceedubs commented Feb 2, 2015

@julien-truffaut that's a good question. Hopefully some good suggestions will come out of this discussion!

@non
Copy link
Contributor

non commented Feb 2, 2015

I agree with @ceedubs -- I think concrete types should provide all the concrete implementations there type classes need.

This can be a bit ugly but it has many benefits:

  1. Things for users are guaranteed to "just work" whenever possible.
  2. You can avoid repeatedly synthesizing type class instances.
  3. It makes the methods more discoverable via documentation / browsing.

Of these concerns I think (2) is the most important.

If we agree with this approach then it implies that at a minimum we should be adding === and =!= methods to our concrete types where applicable, so that they can directly do type-safe equality checking.

@stew
Copy link
Contributor

stew commented Feb 3, 2015

@julien-truffaut seems like there in consensus here, do you think we need to do more with this issue?

@julien-truffaut
Copy link
Contributor Author

sure I think we all agree

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

4 participants