-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allowed modifiers for enums and enum cases #5495
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
Comments
Related: #5034 |
Can we do |
@ctongfei could you elaborate on that a little? What shapeless idiom are you referring to and how do you see implicit cases mapping on to that? |
@milessabin I once created this Shapless-style thing: trait IndexOf[A, U] extends DepFn0 {
type Out <: Nat
def toInt: Int
}
object IndexOf {
def apply[A, U](implicit o: IndexOf[A, U]): Aux[A, U, o.Out] = o
type Aux[A, U, I <: Nat] = IndexOf[A, U] { type Out = I }
implicit def case0[At <: HList, U]: Aux[U :: At, U, _0] =
new IndexOf[U :: At, U] {
type Out = _0
def apply() = Nat._0
def toInt = 0
}
implicit def caseN[At <: HList, Ah, U, I <: Nat]
(implicit p: IndexOf.Aux[At, U, I]): Aux[Ah :: At, U, Succ[I]] =
new IndexOf[Ah :: At, U] {
type Out = Succ[I]
def apply() = Succ[I]()
def toInt = p.toInt + 1
}
} Using enum IndexOf[A, U] extends DepFn0 {
type Out <: Nat
def toInt: Int
implicit case Case0[At <: HList, U] extends IndexOf[U :: At, U] {
type Out = _0
def apply() = Nat._0
def toInt = 0
}
implicit case CaseN[At <: HList, Ah, U, I <: Nat]
(implicit p: IndexOf.Aux[At, U, I]) extends IndexOf[Ah :: At, U] {
type Out = Succ[I]
def apply() = Succ[I]()
def toInt = p.toInt + 1
}
}
|
I see, so the idea would be to use an enum as a shapeless |
@milessabin Yes that's my idea. You summarized it much better than I could. |
@ctongfei Please open a separate issue if you think this is a use case that enums should support. This is out of scope of the current proposal for several reasons:
|
What should be the allowed modifiers for enums and enum cases? What about:
private
,protected
) and annotationsThe text was updated successfully, but these errors were encountered: