```interface IS<T> {fun <T>T.fmap():T}...
# announcements
i
Copy code
interface IS<T> {fun <T>T.fmap():T}
sealed class IIS<T>: IS<T>
data class IntIS<Int>(val x:Int): IIS<Int>(){
    fun Int.fmap(){
        return x+1
    }
}
how to fix this?
d
what were you trying to achieve?
i
if a parameter declare has IIS<T>, so I can put a value has IntIS<Int> on there, and this value has fmap method, just like a typeclass
create a typeclass IS, and require to implement function fmap, then make Int and String as IS's instances, then where a parameter declare it has IS, then I can put Int or String value on there, and that value must have fmap function
generics constraints + interface + class extension
ad-hoc polymorphism
d
something like this? https://pl.kotl.in/u3IuTUInI... not really sure what is your use case... it looks overly complicated design...
k
i
why
return this
can't be
return x+1
in your code? there's (val x: Int) in the constractor
d
u can replace the
this
with
x+1
and the compiler will tell you why that one cannot be done... 😉.. basically, the returned type is different...
i
why? x declared as Int, and the function return Int, so why
return x+1
won't be Int?
k
What are you talking about?
I noticed a mistake from copying Handra's playground, as I was (and still am) on phone.
The issue was that you were shadowing the
Int
type