type infrence failed: Cannot infer type parameter ...
# announcements
i
type infrence failed: Cannot infer type parameter A in fun <A,B,C> either... https://paste.ubuntu.com/p/XFN5NbWnZB/
Copy code
sealed class nEither<A,B>
data class nLeft<A,B>(val v:A): nEither<A,B>()
data class nRight<A,B>(val v:B): nEither<A,B>()

fun <A,B,C> either(f:(A)->C, g:(B)->C, v:nEither<A,B>): C{
   when (v) {
       is nLeft<A,B> -> return f(v.v)
       is nRight<A,B> -> return g(v.v)
   }
}

fun <T> id(x:T):T{
    return x
}

fun main(){
    val z2 = {
        x:T -> x
    }
    either(z2,z2,nLeft<String,Any>("aha"))

}
k
I think you want
class Left<A>(val left: A) : Either<A, Nothing>
i
I change it as what you said, the error is still the same
k
Isn't there already a library for this?
i
arrow? I'm not familiar with it yet, so I'd like to implement it
m
You could 'cheat', and look at Arrow's source code.