type-graphs seem like the domain of haskell/arrow,...
# arrow
j
type-graphs seem like the domain of haskell/arrow, though the java type-graph example i have sort of autocompletes automatically in intellij.
r
type proofs aside, reducing the noise of the syntax above is something you can already accomplish with vanilla Kotlin. It’s just one extension function that overrides an operator. Kotlin is specifically made to create DSLs like this which is what it seems you are trying to accomplish.
Copy code
inline class MyClass(val value: IntArray)

operator fun MyClass.get(range: IntRange): List<Int> = 
  value.filter { it in range }

val myClass: MyClass = MyClass(intArrayOf(0, 1, 2, 3, 4))
val range: List<Int> = myClass[2..5]
j
[edited]
Copy code
typealias myvec = Array<Pair<String, Any?>>
@JvmName("va")
operator fun myvec.get(vararg indexes: Int) = this[indexes]

@JvmName("ip")
private operator fun myvec.get(indexes: Iterable<Int>) =this[indexes.toList().toIntArray()]

@JvmName("squelch")
operator fun myvec.get(indexes: IntArray) = Array(indexes.size) { this[indexes[it]] }

val x = {
    val zyx = listOf("z", "y", "x", "w")
    val testme: myvec = zyx.zip(zyx).toTypedArray()
    val res = testme[3, 2, 1, 0]
    val res2 = testme[3.downTo(0)]
    val res3 = testme[1 until 3]
    val res4 = testme[intArrayOf(3, 2, 1, 0)]
}
r
It can, that’s what type classes do, abstract away abstract algebras from the container they belong to. there is multiple examples in the docs with multiple unrelated containers that show this feature alongside kinds