Before I begin I will post my code to save time in the event that this question is obvious:
let doAtoB (a,b) =
if b < 0 then
1
else
1 + a(a,(b-1))
print_any (doAtoB(doAtoB,5))
I was recently learning about the Y Combinator and was interested in implementing it in F#. I kept getting the same error:
"Type Mismatch: Expecting a 'a but given a 'a * 'b -> int. The resulting type would be infinite when unifying 'a and 'a * 'b -> int"
As the error suggests the type would be growing as:
'a*int -> int
('a*int -> int) * int -> int
(('a*int -> int) *int -> int) * int -> int
So I get that the type is infinite, but there seems to be no way around this. The code should work just fine, it just can't be handled by the type inferencing mechanism. Scheme claims to be able to do this. Is this functionality simply not availible in F#? Is there no way to write a Y Combinator in the language?
Thank you very much to anyone who has an idea what the answer here might be.