【发布时间】:2012-01-10 23:03:27
【问题描述】:
我尝试在 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));
}
【问题讨论】:
-
@JaredPar 我还没有尝试用它构建任何函数,只是试图让定义正确。谢谢。
-
@JaredPar Lukazoid 能够帮助我。还是谢谢。
标签: c# haskell functional-programming fixpoint-combinators