-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make Free/FreeApplicative constructors private #613
Conversation
There are a couple of reasons this might be a good idea. Currently it's possible to observe a difference when calling `.map(identity)` on a `Free` instance: ```scala scala> import cats.free._; import cats.implicits._ import cats.free._ import cats.implicits._ scala> def f(x: Free[Option, Int]) = x match { | case Free.Pure(i) => i | case _ => 0 | } f: (x: cats.free.Free[Option,Int])Int scala> val x: Free[Option, Int] = Free.pure(3) x: cats.free.Free[Option,Int] = Pure(3) scala> f(x) res0: Int = 3 scala> f(x.map(identity)) res1: Int = 0 ``` Making these private also frees us up to change the internal representation in the future without breaking user code.
If I remember correctly I made this change before but reverted it - on one hand hiding the constructors ensures lawful-ness.. on the other hand hiding constructors prevents users from writing their own tail-recursive implementation, though perhaps we can say the methods we provide on |
The place where I definite care about this is |
(There's also a legitimate Travis build failure.) |
Also make TrampolineFunctions package-private, since it's just a workaround for a scalac bug and isn't really intended to be used directly.
Current coverage is
|
Thanks for the input @adelbertc and @non. I'm inclined to make these private for the reasons stated in my original comment. It's always easier to open them up in the future if people need access to them for custom tail-recursive methods than it is to remove them once they are part of a public API. I would guess that people are more likely to want to write custom tail-recursive methods for I've also fixed the build error (thanks Travis). |
I'm fine with making these private (and opening them up later if necessary). I just wanted to make the argument for why some types (e.g. |
👍 |
Squash? :) |
@refried I can squash if people want me to, but I think per Cats contributor guidelines that would mean closing this PR and opening a new one from a different branch which seems like it might be overkill for just having one extra commit. Happy to do whatever people want, though. |
@ceedubs Oops, I hadn’t read them! I wasn’t trying to reduce the number of commits in the PR, but reduce the number of non-compiling commits. Maybe it’s not a big deal though? |
👍 |
Make Free/FreeApplicative constructors private
There are a couple of reasons this might be a good idea.
Currently it's possible to observe a difference when calling
.map(identity)
on aFree
instance:Making these private also frees us up to change the internal
representation in the future without breaking user code.