fantasy-land: Apply composition law does not equate
It could be that my implementation is not correct, but here’s the result of the test.
test.js
"use strict";
class Thing {
constructor(value) {
this.value = value;
}
ap(other) { return other.map(this.value); }
map(f) { return new Thing(f(this.value)); }
}
const y = new Thing(x => x);
const left = y.ap(y.ap(y.map(f => g => x => f(g(x)))));
const right = y.ap(y).ap(y)
console.log("left === right:", left === right);
console.log("left value:", left.value.toString());
console.log("right value:", right.value.toString());
Running test.js
$ node test
left === right: false
left value: g => x => f(g(x))
right value: x => x
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (11 by maintainers)
Don’t contaminate your thoughts with this sort of comparison. 😉
I suggest comparing
ap
tomap
. They’re very similar:The type signatures are instructive:
ap
exists in Prelude as well.