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
Explore Derivation Of Functional Abstractions #1079
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good initiative 👍
final case class Person(name: String, age: Int) | ||
|
||
sealed trait Color |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come you don't need the derives Equal
clauses? I though that you need to use them 🤔
https://docs.scala-lang.org/scala3/reference/contextual/derivation.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently not.
|
||
trait EqualVersionSpecific { | ||
|
||
inline given derived[A](using mirror: Mirror.Of[A]): Equal[A] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline given derived[A](using mirror: Mirror.Of[A]): Equal[A] = | |
inline def derived[A](using mirror: Mirror.Of[A]): Equal[A] = |
Otherwise it will derive for all types with no control right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given
is in the documentation of this feature and using def
creates an infinite loop in the derivation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I've been alluding to in my comment above: #1079 (comment)
I also think that people would like to control it with derives Equal
clauses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened an issue with the Scala 3 team regarding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def
creates an infinite loop in the derivation.
Erf that is ... weird. This code is equivalent to fully automatic derivation. With a def
users would need to explicitly add the derives
clause. I had many complaints with scanamo when instances were created implicitly.
I read the docs, the "recursively auto-derive" is an anti pattern imo, oh well I guess time will tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So also according to @bishabosha we shouldn't put the given
on the derived method to let the derivations be driven by derives
clauses.
using
def
creates an infinite loop in the derivation
Are you able replicate it? Maybe we should report that.
I'm trying my lack with changing the official documentation scala/scala3#16919 Let's see where this leads 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given
is in the documentation of this feature and usingdef
creates an infinite loop in the derivation.
is the infinite loop with any type, or a specific example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The derivation for Color
.
No description provided.