Y-combinator with memoization