In scala I am wondering if there is a way I can define a new type including itself For example
type A = Tuple(e1: Int, e2: A)
Ofcourse type A = List[A] is illegal so is there another way to do this?
I tried doing this with type Any and Option but it didn't go well, and I am not sure this is a right way to do this
You can try
Now there is no way to construct a value of type
A(not usingnull) so you should add a "leaf" besides the "fork"Tuple.Infinite recursive type
type A = Tuple[Int, A]is forbiddenFor recursive calculations on types you can use type projections
and
Another option is type classes
(For some reason Scala 2.13 by-name implicits
=>and path-dependent typeaol.value.Outdo not work in 2.13.10: 1 2).In Scala 3 you can use match types and compile-time operations