我尝试在 C# 中定义一个定点生成器,您可以在许多函数式语言中看到它。我相信 foldr 有时通常是根据定点生成器来定义的。我将展示它的 Haskell 定义,然后展示我在 C# 中的定义。任何帮助是极大的赞赏。
//Haskell
fix f = f (fix f)
//C# (Many attempts)
public static Func<Func<T, T>, T> Combinator1<T>(this Func<T, T> f)
{
return x => f(Combinator1(f)(x));
}
public static Func<Func<T, T>, T> Combinator2<T>(this Func<T, T> f)
{
return x => x(Combinator2(x)(f));
}
public static Func<T, U> Combinator3<T, U>(Func<Func<T, U>, Func<T, U>> f)
{
return f(x => Combinator3(f)(x));
}