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); } }
/** * fmap id == id */ public function testFunctorLaw1() { $id = id(); $a = f(function ($a) { return $a + 1; }); $left = fmap($id); $right = $id; $this->assertEquals(4, $left($a)->apply(3)); $this->assertEquals($left($a)->apply(3), $right($a)->apply(3)); }