Re: Distinguishing case class members

Naftoli Gugenheim <[email protected]> Sun, 10 Jan 2016 13:07:32 +0000
Newsgroups gmane.comp.lang.scala
Message-ID <CANpg8PD66hH5G8Lm3spJb9gdTpvPA+zaK4WkBH0gJ-jRLrt0mA@mail.gmail.com>
On Sat, Dec 26, 2015 at 5:22 AM Peter Empen <[email protected]> wrote:

> Currently all parameters of the first parameter list go into the generated
> equals/hashCode/copy/unapply methods.
> This works well for most cases but sometimes we need to *exclude* some
> parameters from equals/hashCode while keeping them copy and matchable.
>
> Now, to relieve programmers from the burden of defining custom
> equals/hashCode in such situations, it would be great to have some direct
> means to advise the compiler which parameters should *not *go into
> equals/hashCode.
>

Rather than putting them in the primary parameter list and  defining a
custom equals/hashCode, it seems a lot easier to put them in a secondary
parameter list, which requires solving two problems as you mentioned, copy
and pattern matching. For copy, it seems you can create your own copy
method with a different name (copy2 say) for the extra parameters; that
should not be too difficult. And for pattern matching you can just use a
guard, or select them from the matched object ( a match { case x @ X(1, _)
=> x.c })

It would be nice to automate the above, but I think doing so is an easier
target than changing the way the compiler generates copy and pattern
matching.



>
> One approach could be to provide a specific member-level annotation for
> this purpose.
> Another approach could be to let val-/non-implicit-members of any
> secondary parameter list become a parameter of copy automatically.
> Maybe you have even a better approach.
>
> What do you think about this proposal?
>
> --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.