https://kotlinlang.org logo
#announcements
Title
# announcements
i

Ifvwm

08/27/2019, 3:56 AM
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

karelpeeters

08/27/2019, 6:12 AM
I think you want
class Left<A>(val left: A) : Either<A, Nothing>
i

Ifvwm

08/27/2019, 6:54 AM
I change it as what you said, the error is still the same
k

Kroppeb

08/27/2019, 8:15 AM
Isn't there already a library for this?
i

Ifvwm

08/27/2019, 8:36 AM
arrow? I'm not familiar with it yet, so I'd like to implement it
m

Mike

08/27/2019, 11:45 AM
You could 'cheat', and look at Arrow's source code.
2 Views