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

Scala 3 book should describe aggregate bounds (e.g. for typeclasses) #3179

Open
smheidrich opened this issue Mar 24, 2025 · 0 comments
Open

Comments

@smheidrich
Copy link

smheidrich commented Mar 24, 2025

The Scala 3 book's section on writing methods that use type classes only shows how to specify a single type class as a parameter's bound.

How to specify multiple bounds is described in the Aggregate Context Bounds section of the reference:

  def showMax[X : {Ord as ordering, Show as show}](x: X, y: X): String =
    show.asString(ordering.max(x, y))

As far as I can tell, this syntax isn't described anywhere in the book, and it's not exactly intuitive.

So in my opinion, it would be nice if this syntax (or its alternatives for older Scala versions) was explained anywhere in the Scala 3 book. Maybe it doesn't have to be in the type class section because it is about bounds more generally, although it may also be worth pointing out how the as syntax specifically is useful for disambiguating between different type classes that have some identically named methods (cf. e.g. Rust's book which has an entire section on how to handle this case).

@smheidrich smheidrich changed the title Scala 3 book should describe how to have more than one typeclass as a bound Scala 3 book should describe how to have more than one bound (e.g. when using typeclasses) Mar 24, 2025
@smheidrich smheidrich changed the title Scala 3 book should describe how to have more than one bound (e.g. when using typeclasses) Scala 3 book should describe aggregate bounds (e.g. when using typeclasses) Mar 24, 2025
@smheidrich smheidrich changed the title Scala 3 book should describe aggregate bounds (e.g. when using typeclasses) Scala 3 book should describe aggregate bounds (e.g. for typeclasses) Mar 24, 2025
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

1 participant