function const2(...$args) { $f = function ($a1, $a2) { return ap(fconst(id(), $a1), $a2); }; if (count($args) === 2) { return $f(...$args); } else { return f($f, ...$args); } }
public function testGuardAppend() { $f = function ($s, ...$eq) { return f(function ($s, $a, $b) { return fconst($s, guard($a === $b)); }, $s, ...$eq); }; $at = $f('a', 1, 1); $af = $f('a', 1, 2); $bt = $f('b', 2, 2); $bf = $f('b', 2, 3); $this->assertEquals(Just('a'), $at->cast(Nothing())); $this->assertEquals(Nothing(), $af->cast(Nothing())); $this->assertEquals(Just('b'), $bt->cast(Nothing())); $this->assertEquals(Nothing(), $bf->cast(Nothing())); $this->assertEquals(Nothing(), mappend($af, $bf)->cast(Nothing())); $this->assertEquals(Just('a'), mappend($at, $bf)->cast(Nothing())); $this->assertEquals(Just('b'), mappend($af, $bt)->cast(Nothing())); $this->assertEquals(Just('ab'), mappend($at, $bt)->cast(Nothing())); $this->assertEquals(Nothing(), mappend($f('a', 1), $f('b', 1), 2)->cast(Nothing())); $this->assertEquals(Just('a'), mappend($f('a', 2), $f('b', 1), 2)->cast(Nothing())); $this->assertEquals(Just('b'), mappend($f('a', 1), $f('b', 2), 2)->cast(Nothing())); $this->assertEquals(Just('ab'), mappend($f('a', 2), $f('b', 2), 2)->cast(Nothing())); }
public function testFconst() { $this->assertEquals(Just(1), fconst(1, Just(2))); $this->assertEquals(Nothing(), fconst(1, Nothing())); }