@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public static function eight(): Closure |
20 | 20 | { |
21 | - return static fn (callable $s) => static fn ($z) => $s($s($s($s($s($s($s($s($z)))))))); |
|
21 | + return static fn(callable $s) => static fn($z) => $s($s($s($s($s($s($s($s($z)))))))); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public static function exponentiation(): Closure |
25 | 25 | { |
26 | - return static fn (callable $f): Closure => static fn (callable $n): Closure => $n($f); |
|
26 | + return static fn(callable $f): Closure => static fn(callable $n): Closure => $n($f); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public static function five(): Closure |
33 | 33 | { |
34 | - return static fn (callable $s): Closure => static fn ($z) => $s($s($s($s($s($z))))); |
|
34 | + return static fn(callable $s): Closure => static fn($z) => $s($s($s($s($s($z))))); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public static function four(): Closure |
41 | 41 | { |
42 | - return static fn (callable $s): Closure => static fn ($z) => $s($s($s($s($z)))); |
|
42 | + return static fn(callable $s): Closure => static fn($z) => $s($s($s($s($z)))); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | public static function minus(): Closure |
46 | 46 | { |
47 | - return static fn (callable $x): Closure => static fn (callable $y): Closure => $y(self::pred())($x); |
|
47 | + return static fn(callable $x): Closure => static fn(callable $y): Closure => $y(self::pred())($x); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public static function multiply(): Closure |
51 | 51 | { |
52 | - return static fn (callable $x): Closure => static fn (callable $y): Closure => $x(self::plus()($y))(self::zero()); |
|
52 | + return static fn(callable $x): Closure => static fn(callable $y): Closure => $x(self::plus()($y))(self::zero()); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public static function nine(): Closure |
59 | 59 | { |
60 | - return static fn (callable $s): Closure => static fn ($z) => $s($s($s($s($s($s($s($s($s($z))))))))); |
|
60 | + return static fn(callable $s): Closure => static fn($z) => $s($s($s($s($s($s($s($s($s($z))))))))); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,21 +65,20 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public static function one(): Closure |
67 | 67 | { |
68 | - return static fn (callable $s): Closure => static fn ($z) => $s($z); |
|
68 | + return static fn(callable $s): Closure => static fn($z) => $s($z); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | public static function plus(): Closure |
72 | 72 | { |
73 | - return static fn (callable $a): Closure => static fn (callable $b): Closure => static fn ($c): Closure => static fn ($d) => $b($c)($a($c)($d)); |
|
73 | + return static fn(callable $a): Closure => static fn(callable $b): Closure => static fn($c): Closure => static fn($d) => $b($c)($a($c)($d)); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public static function pred(): Closure |
77 | 77 | { |
78 | - return static fn (callable $n): Closure => static fn (callable $next): Closure => static fn ($first) => Pair::second()( |
|
78 | + return static fn(callable $n): Closure => static fn(callable $next): Closure => static fn($first) => Pair::second()( |
|
79 | 79 | $n( |
80 | - static fn (callable $pair): Closure => Pair::first()($pair) ? |
|
81 | - Pair::of()(false)($first) : |
|
82 | - Pair::of()(false)($next(Pair::second()($pair))) |
|
80 | + static fn(callable $pair): Closure => Pair::first()($pair) ? |
|
81 | + Pair::of()(false)($first) : Pair::of()(false)($next(Pair::second()($pair))) |
|
83 | 82 | )(Pair::of()(true)($first)) |
84 | 83 | ); |
85 | 84 | } |
@@ -89,7 +88,7 @@ discard block |
||
89 | 88 | */ |
90 | 89 | public static function seven(): Closure |
91 | 90 | { |
92 | - return static fn (callable $s) => static fn ($z) => $s($s($s($s($s($s($s($z))))))); |
|
91 | + return static fn(callable $s) => static fn($z) => $s($s($s($s($s($s($s($z))))))); |
|
93 | 92 | } |
94 | 93 | |
95 | 94 | /** |
@@ -97,12 +96,12 @@ discard block |
||
97 | 96 | */ |
98 | 97 | public static function six(): Closure |
99 | 98 | { |
100 | - return static fn (callable $s) => static fn ($z) => $s($s($s($s($s($s($z)))))); |
|
99 | + return static fn(callable $s) => static fn($z) => $s($s($s($s($s($s($z)))))); |
|
101 | 100 | } |
102 | 101 | |
103 | 102 | public static function succ(): Closure |
104 | 103 | { |
105 | - return static fn (callable $n): Closure => static fn (callable $s): Closure => static fn ($z) => $s($n($s)($z)); |
|
104 | + return static fn(callable $n): Closure => static fn(callable $s): Closure => static fn($z) => $s($n($s)($z)); |
|
106 | 105 | } |
107 | 106 | |
108 | 107 | /** |
@@ -110,12 +109,12 @@ discard block |
||
110 | 109 | */ |
111 | 110 | public static function three(): Closure |
112 | 111 | { |
113 | - return static fn (callable $s) => static fn ($z) => $s($s($s($z))); |
|
112 | + return static fn(callable $s) => static fn($z) => $s($s($s($z))); |
|
114 | 113 | } |
115 | 114 | |
116 | 115 | public static function toInt(callable $numeral) |
117 | 116 | { |
118 | - return $numeral(static fn (int $n): int => $n + 1)(0); |
|
117 | + return $numeral(static fn(int $n): int => $n + 1)(0); |
|
119 | 118 | } |
120 | 119 | |
121 | 120 | /** |
@@ -123,7 +122,7 @@ discard block |
||
123 | 122 | */ |
124 | 123 | public static function two(): Closure |
125 | 124 | { |
126 | - return static fn (callable $s) => static fn ($z) => $s($s($z)); |
|
125 | + return static fn(callable $s) => static fn($z) => $s($s($z)); |
|
127 | 126 | } |
128 | 127 | |
129 | 128 | /** |
@@ -131,6 +130,6 @@ discard block |
||
131 | 130 | */ |
132 | 131 | public static function zero(): Closure |
133 | 132 | { |
134 | - return static fn (callable $s) => static fn ($z) => $z; |
|
133 | + return static fn(callable $s) => static fn($z) => $z; |
|
135 | 134 | } |
136 | 135 | } |
@@ -15,66 +15,66 @@ |
||
15 | 15 | { |
16 | 16 | public static function CAnd(): Closure |
17 | 17 | { |
18 | - return static fn (callable $l): Closure => static fn (callable $c): Closure => $l($c)(self::CFalse()); |
|
18 | + return static fn(callable $l): Closure => static fn(callable $c): Closure => $l($c)(self::CFalse()); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function CFalse(): Closure |
22 | 22 | { |
23 | - return static fn ($t): Closure => static fn ($f) => $f; |
|
23 | + return static fn($t): Closure => static fn($f) => $f; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public static function CIf(): Closure |
27 | 27 | { |
28 | - return static fn (callable $if): Closure => self::CTrue()($if)(self::CFalse()); |
|
28 | + return static fn(callable $if): Closure => self::CTrue()($if)(self::CFalse()); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public static function CNot(): Closure |
32 | 32 | { |
33 | - return static fn (callable $fn): Closure => $fn(self::CFalse())(self::CTrue()); |
|
33 | + return static fn(callable $fn): Closure => $fn(self::CFalse())(self::CTrue()); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | public static function COr(): Closure |
37 | 37 | { |
38 | - return static fn (callable $l): Closure => static fn (callable $c): Closure => $l(self::CTrue())($c); |
|
38 | + return static fn(callable $l): Closure => static fn(callable $c): Closure => $l(self::CTrue())($c); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public static function CTrue(): Closure |
42 | 42 | { |
43 | - return static fn ($t): Closure => static fn ($f) => $t; |
|
43 | + return static fn($t): Closure => static fn($f) => $t; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | public static function CXor(): Closure |
47 | 47 | { |
48 | - return static fn (callable $a): Closure => static fn (callable $b) => ($a($b(self::CFalse())(self::CTrue())))($b(self::CTrue())(self::CFalse())); |
|
48 | + return static fn(callable $a): Closure => static fn(callable $b) => ($a($b(self::CFalse())(self::CTrue())))($b(self::CTrue())(self::CFalse())); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public static function eq(): Closure |
52 | 52 | { |
53 | - return static fn ($a): Closure => static fn ($b) => self::CAnd()(self::lte()($a)($b))(self::lte()($b)($a)); |
|
53 | + return static fn($a): Closure => static fn($b) => self::CAnd()(self::lte()($a)($b))(self::lte()($b)($a)); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | public static function gt(): Closure |
57 | 57 | { |
58 | - return static fn ($a): Closure => static fn ($b) => self::CNot()(self::lte()($a)($b)); |
|
58 | + return static fn($a): Closure => static fn($b) => self::CNot()(self::lte()($a)($b)); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | public static function gte(): Closure |
62 | 62 | { |
63 | - return static fn ($a): Closure => static fn ($b) => self::isZero()(Numeral::minus()($b)($a)); |
|
63 | + return static fn($a): Closure => static fn($b) => self::isZero()(Numeral::minus()($b)($a)); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | public static function isZero(): Closure |
67 | 67 | { |
68 | - return static fn ($a) => $a(static fn () => self::CFalse())(self::CTrue()); |
|
68 | + return static fn($a) => $a(static fn() => self::CFalse())(self::CTrue()); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | public static function lt(): Closure |
72 | 72 | { |
73 | - return static fn ($a): Closure => static fn ($b) => self::CNot()(self::gte()($a)($b)); |
|
73 | + return static fn($a): Closure => static fn($b) => self::CNot()(self::gte()($a)($b)); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public static function lte(): Closure |
77 | 77 | { |
78 | - return static fn ($a): Closure => static fn ($b) => self::isZero()(Numeral::minus()($a)($b)); |
|
78 | + return static fn($a): Closure => static fn($b) => self::isZero()(Numeral::minus()($a)($b)); |
|
79 | 79 | } |
80 | 80 | } |
@@ -16,33 +16,32 @@ discard block |
||
16 | 16 | { |
17 | 17 | public static function concat(): Closure |
18 | 18 | { |
19 | - return static fn ($xs): Closure => static fn ($ys): Closure => self::foldr()(self::cons())($ys)($xs); |
|
19 | + return static fn($xs): Closure => static fn($ys): Closure => self::foldr()(self::cons())($ys)($xs); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function cons() |
23 | 23 | { |
24 | - return static fn ($a): Closure => static fn ($b): Closure => Pair::of()(false)(Pair::of()($a)($b)); |
|
24 | + return static fn($a): Closure => static fn($b): Closure => Pair::of()(false)(Pair::of()($a)($b)); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public static function foldl() |
28 | 28 | { |
29 | - return static fn ($f) => static fn ($a) => static fn ($xs) => self::foldr()( |
|
30 | - static fn ($x) => static fn ($g) => static fn ($y) => $g($f($y)($x)) |
|
31 | - )(static fn ($x) => $x)($xs)($a); |
|
29 | + return static fn($f) => static fn($a) => static fn($xs) => self::foldr()( |
|
30 | + static fn($x) => static fn($g) => static fn($y) => $g($f($y)($x)) |
|
31 | + )(static fn($x) => $x)($xs)($a); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public static function foldr() |
35 | 35 | { |
36 | 36 | return Combinators::Y()( |
37 | - static fn ($r) => static fn ($f) => static fn ($a) => static fn ($xs) => self::isNil()($xs) ? |
|
38 | - (static fn () => $a) : |
|
39 | - (static fn () => $f(self::head()($xs))($r($f)($a)(self::tail()($xs))))() |
|
37 | + static fn($r) => static fn($f) => static fn($a) => static fn($xs) => self::isNil()($xs) ? |
|
38 | + (static fn() => $a) : (static fn() => $f(self::head()($xs))($r($f)($a)(self::tail()($xs))))() |
|
40 | 39 | ); |
41 | 40 | } |
42 | 41 | |
43 | 42 | public static function head() |
44 | 43 | { |
45 | - return static fn ($a): Closure => Pair::first()(Pair::second()($a)); |
|
44 | + return static fn($a): Closure => Pair::first()(Pair::second()($a)); |
|
46 | 45 | } |
47 | 46 | |
48 | 47 | public static function isNil() |
@@ -52,7 +51,7 @@ discard block |
||
52 | 51 | |
53 | 52 | public static function length() |
54 | 53 | { |
55 | - return self::foldl()(static fn ($a) => static fn ($b) => Numeral::succ()($a))(Numeral::zero()); |
|
54 | + return self::foldl()(static fn($a) => static fn($b) => Numeral::succ()($a))(Numeral::zero()); |
|
56 | 55 | } |
57 | 56 | |
58 | 57 | public static function nil() |
@@ -62,13 +61,13 @@ discard block |
||
62 | 61 | |
63 | 62 | public static function range() |
64 | 63 | { |
65 | - return static fn ($a): Closure => static fn ($b) => Numeral::minus()(Numeral::succ()($b))($a)(static fn ($c) => CList::cons()(Numeral::minus()($b)(CList::length()($c)))($c))(CList::nil()); |
|
64 | + return static fn($a): Closure => static fn($b) => Numeral::minus()(Numeral::succ()($b))($a)(static fn($c) => CList::cons()(Numeral::minus()($b)(CList::length()($c)))($c))(CList::nil()); |
|
66 | 65 | } |
67 | 66 | |
68 | 67 | public static function repeat() |
69 | 68 | { |
70 | - return static fn ($a): Closure => static fn (callable $b) => $b( |
|
71 | - static fn ($c) => CList::cons()($a)($c) |
|
69 | + return static fn($a): Closure => static fn(callable $b) => $b( |
|
70 | + static fn($c) => CList::cons()($a)($c) |
|
72 | 71 | )(CList::nil()); |
73 | 72 | } |
74 | 73 | |
@@ -79,6 +78,6 @@ discard block |
||
79 | 78 | |
80 | 79 | public static function tail(): Closure |
81 | 80 | { |
82 | - return static fn ($a): Closure => Pair::second()(Pair::second()($a)); |
|
81 | + return static fn($a): Closure => Pair::second()(Pair::second()($a)); |
|
83 | 82 | } |
84 | 83 | } |