I, personally, don’t think that borrowing Scala’s ...
# functional
e
I, personally, don’t think that borrowing Scala’s implicit is a good idea. IMHO, something that is directly designed for support of type-classes might be easier to use and less prone to abuse. Of course, it is going to have some implicit parameters behind the scenes, but having an implicit user-experience is not user-friendly — too much typing and too indirect thought process is required. I suggest to work on the idea of having type-classes without implicits. Here is some syntactic direction that might work better:
Copy code
typeclass Semigroup {
    fun combine(b: Self): Self
}

extension Int : Semigroup {
    fun combine(b: Int): Int = this + b
}

fun add(a: Int, b: Int): Int = a.combine(b) //compiles because combine is normal extension fun for Int
fun <A : Semigroup> add(a: A, b: A): A = a.combine(b) //compiles, because every Semigroup type must have combine extension
This is a purely straw-man proposal (let’s not bikeshed about naming and declaration syntax), but see how much it is easier to use and how it nicely builds upon the Kotlin concept of extension functions.
👍 9