Hi, This code does not compile ('Type checking ha...
# arrow
p
Hi, This code does not compile ('Type checking has run into a recursive problem')
Copy code
val eitherMonad = Either.monad<String>()
fun stackSafeEitherProgram(n: Int, acc: Int)  =
    eitherMonad.fx.stackSafe {
        val r = when  {
            n == 0 -> !Right(acc)
            n > 0 -> n * stackSafeEitherProgram(n-1, acc).bind()
            else -> !Left("Invalid number!")
        }
        r
    }
Not sure that you can improve this type checking...