I was able to get it to work with just overriding ...
# arrow-meta
r
I was able to get it to work with just overriding the Type Checker. This program now type checks, compiles and runs:
Copy code
sealed class Option<out A> {
  fun h(): Option<Int> {
    val x : OptionOf<Int> = None
    val y = x
    return y
  }
}

object None : Option<Nothing>()

data class Some<out A>(val a: A) : Option<A>()

object test {
  @JvmStatic
  fun main(args: Array<String>) {
    println("Option supertypes: ${Option::class.java.interfaces.toList().map { it.toGenericString() }}")
    println("For Option Class through reflection:" + Class.forName("arrow.sample.ForOption"))
    println(None.h())
  }
}
Notice how
None.f: Option<Int>
internally has an implicit conversion from the
OptionOf
type to the
Option
despite
Option<A>: OptionOf<A>
also being synthetic 🙂.
return y
is of type
OptionOf
but the Type checker is now kind aware so it knows it refers to the same value and returns true for their subtype relationship whther the value is typed to its kinded form or to the concrete type. It prints:
Copy code
Option supertypes: [public abstract interface arrow.sample.Kind<F,A>]
For Option Class through reflection:class arrow.sample.ForOption
arrow.sample.None@76ed5528
👏 3