public class YCombinator
{
private const int Max = 12_000;
private readonly Arbitrary<int> PositiveNumbers = Arb.From(Gen.Choose(0, Max));
private static readonly Func<int, int> sum =
n =>
n == 0 ? 0 : n + sum(n - 1);
[Property]
Property it_meets_the_gauss_formula() =>
ForAll(PositiveNumbers, n =>
sum(n) == n * (n + 1) / 2);
}
private delegate int Sum(int n);
private static readonly Sum sum =
n =>
n == 0 ? 0 : n + sum(n - 1);
MkSum
with Extract Methoddelegate int Sum(int n);
static readonly Sum sum =
MkSum();
static Sum MkSum() =>
n =>
n == 0 ? 0 : n + sum(n-1);
sum
float updelegate int Sum(int n);
static readonly Sum sum =
MkSum(sum);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
sum
lazydelegate int Sum(int n);
static readonly Sum sum =
n =>
MkSum(sum)(n);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
public class YCombinator
{
private const int Max = 8_000;
private readonly Arbitrary<int> PositiveNumbers = Arb.From(Gen.Choose(0, Max));
[...]
delegate int Sum(int n);
delegate Sum MkSum(Sum continuation);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Sum Y() =>
MkSum(sum);
static readonly Sum sum =
n =>
Y()(n);
MkSum
as a parameterdelegate int Sum(int n);
delegate Sum MkSum(Sum continuation);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Sum Y(Func<Sum, Sum> f) =>
f(sum);
static readonly Sum sum =
n =>
Y(MkSum)(n);
sum
to Y
delegate int Sum(int n);
delegate Sum MkSum(Sum continuation);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Sum Y(Fun<Sum, Sum> f) =>
n =>
f(sum)(n);
static readonly Sum sum =
Y(MkSum);
sum
with Y(MkSum)
delegate int Sum(int n);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Sum Y(MkSum f) =>
n =>
f(Y(f))(n);
static readonly Sum sum =
Y(MkSum);
Y
to fielddelegate int Sum(int n);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Func<Func<Sum, Sum>, Sum> Y =
f =>
n => f(Y(f))(n);
static readonly Sum sum =
Y(MkSum);
public class YCombinator
{
private const int Max = 12_000;
private readonly Arbitrary<int> PositiveNumbers = Arb.From(Gen.Choose(0, Max));
private static readonly Func<int, int> sum =
n =>
n == 0 ? 0 : n + sum(n - 1);
[Property]
Property it_meets_the_gauss_formula() =>
ForAll(PositiveNumbers, n =>
sum(n) == n * (n + 1) / 2);
}
private delegate int Sum(int n);
private static readonly Sum sum =
n =>
n == 0 ? 0 : n + sum(n - 1);
MkSum
with Extract Methoddelegate int Sum(int n);
static readonly Sum sum =
MkSum();
static Sum MkSum() =>
n =>
n == 0 ? 0 : n + sum(n-1);
sum
float updelegate int Sum(int n);
static readonly Sum sum =
MkSum(sum);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
sum
lazyprivate const int Max = 8_000;
private readonly Arbitrary<int> PositiveNumbers = Arb.From(Gen.Choose(0, Max));
delegate int Sum(int n);
static readonly Sum sum =
n =>
MkSum(sum)(n);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
delegate int Sum(int n);
delegate Sum MkSum(Sum continuation);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Sum Y() =>
MkSum(sum);
static readonly Sum sum =
n =>
Y()(n);
MkSum
as a parameterdelegate int Sum(int n);
delegate Sum MkSum(Sum continuation);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Sum Y(Func<Sum, Sum> f) =>
f(sum);
static readonly Sum sum =
n =>
Y(MkSum)(n);
sum
to Y
delegate int Sum(int n);
delegate Sum MkSum(Sum continuation);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Sum Y(Fun<Sum, Sum> f) =>
n =>
f(sum)(n);
static readonly Sum sum =
Y(MkSum);
sum
with Y(MkSum)
delegate int Sum(int n);
static Sum MkSum(Sum continuation) =>
n =>
n == 0 ? 0 : n + continuation(n-1);
static Sum Y(MkSum f) =>
n =>
f(Y(f))(n);
static readonly Sum sum =
Y(MkSum);
Y(mkSum)
with sub
sub
Y
to a local functionn => f(Y(mkSum))(n)
a variableprivate static Sum Y(Func<Sum, Sum> f)
{
Sum sum1 = n => f(Y(f))(n);
return sum1;
}
private static Sum Y(Func<Sum, Sum> f)
{
Sum sub() =>
n => f(Y(f))(n);
Sum sum1 = sub();
return sum1;
}
private static readonly Sum sum =
Y(mkSum);
private static Sum Y(Func<Sum, Sum> f)
{
Sum sub() =>
n => f(Y(f))(n);
return sub();
}
Y(f)
with sub()
private static Sum Y(Func<Sum, Sum> f)
{
Sum sub() =>
n => f(sub())(n);
return sub();
}
private delegate Sum Rec(Rec self);
private static Sum Y(Func<Sum, Sum> f)
{
Sum sub(Rec self) =>
n => f(sub(self))(n);
return sub(sub);
}
sub
with self
private delegate Sum Rec(Rec self);
private static Sum Y(Func<Sum, Sum> f)
{
Sum sub(Rec self) =>
n => f(self(self))(n);
return sub(sub);
}
sub(sub)
with lambdaprivate static Sum Y(Func<Sum, Sum> f)
{
Sum sub(Rec self) =>
n => f(self(self))(n);
return Func<Rec, Sum>(f => f(f))(sub);
}
sub
private static Sum Y(Func<Sum, Sum> f) =>
new Func<Rec, Sum>(f =>
f(f))
(self =>
n =>
f(self(self))(n));