https://kotlinlang.org logo
#arrow
Title
j

jacob

05/21/2018, 8:17 AM
Copy code
@higherkind
sealed class O<A>: OOf<A> {
    class None<A>: O<A>()
    class Some<A>(val t: A): O<A>()
    companion object
}

@instance(O::class)
interface OShowInstance<A> : Show<OOf<A>> {
    fun SA(): Show<A>

    override fun OOf<A>.show(): String {
        val x = this.fix()

        return when (x) {
            is O.None -> "None"
            is O.Some -> "Some(${SA().run { x.t.show() }})"
        }
    }
}



fun main(args: Array<String>) {
    O.show<O<Int>>(O.show(Int.show())).run {
        O.Some(O.Some(1)).show().let(::println)
    }
}