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

Explore Derivation Of Functional Abstractions #1079

Merged
merged 4 commits into from Feb 14, 2023

Conversation

adamgfraser
Copy link
Contributor

No description provided.

@adamgfraser adamgfraser requested a review from a team as a code owner February 14, 2023 15:38
Copy link
Member

@sideeffffect sideeffffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good initiative 👍

Comment on lines +8 to +10
final case class Person(name: String, age: Int)

sealed trait Color
Copy link
Member

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

Copy link
Contributor Author

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] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

scala/scala3#16916

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 😄

Copy link

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.

is the infinite loop with any type, or a specific example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The derivation for Color.

@adamgfraser adamgfraser merged commit f2a5289 into zio:series/2.x Feb 14, 2023
@adamgfraser adamgfraser deleted the derivation branch February 14, 2023 18:03
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

Successfully merging this pull request may close these issues.

None yet

5 participants