I am trying to use y-combinator to define gcd in scala:
object Main { def y[A,B]( f : (A => B) => A => B ) : A => B = f(y(f)) def gcd = y[(Int,Int),Int]( (g) => (x,y) => if (x == 0) y else g(y % x, x) ) }
But I get an error message:
Main.scala:3: error: type mismatch; found : (Int, Int) => Int required: (Int, Int) => Int def gcd = y[(Int,Int),Int]( (g) => (x :Int,y :Int) => if (x == 0) y else g(y % x, x) ) ^
If I archive all the arguments, then there is no problem:
def gcd = y[Int,Int => Int]( g => x => y => if (x == 0) y else g(y % x)(x) )
What am I doing wrong in an unpublished version?
source share