-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply algebra doesn't dispatch correctly to fantasy-land #440
Comments
Awesome. We have an issue for starting work on this here. We also need to make adjustments to each We may be removing fantasy-land entirely, but will post up an issue for the community to debate the direction. As far as dependencies got, we do not want to be tied to dependencies, especially around fantasy-land. That is why we do not use things like Will keep this open to track the work after |
But. We may be able to just update the point free function, and worry about the fl dispatch on the crocks types for now, will need to think that trough on what the transition will be like. Also this will affect the lift functions, so you can verify by using |
Ohhh. also, I think that implementation of class Just {
[fl.ap](m) {
return this[fl.map](m.x)
}
}
// These are now:
const add5 = Just.of(R.add(5))
// Manual `ap` call works:
console.log(Just.of(15)[fl.ap](add5))
// Ramda's `ap` works:
console.log(R.ap(add5)(Just.of(20)))
// Crocks' `ap` FAILS:
console.log(C.ap(add5)(Just.of(25))) This comes from the Appy spec, so with those pointfree functions the data is the last, so that should be the value to be applied.
|
You're totally right, I was struggling a bit with that. I'm still learning about algebraic programming. Thanks for the tip! Incidentally, it's also the reason I couldn't get Sanctuary's const R = require('ramda')
const S = require('sanctuary')
const C = require('crocks')
class Just {
constructor(x) {
this.x = x
}
static of(x) {
return new Just(x)
}
[fl.map](f) {
return Just.of(f(this.x))
}
[fl.ap](m) {
return this[fl.map](m.x)
}
[fl.chain](f) {
return f(this.x)
}
[inspect]() {
return `Just ${this.x[inspect] ? this.x[inspect]() : this.x}`
}
}
// Manual `ap` call
console.log(Just.of(15)[fl.ap](add5))
//=> Just 20
// Ramda's `ap`
console.log(R.ap(add5)(Just.of(20)))
//=> Just 25
// Sanctuary's `ap`
console.log(S.ap(add5)(Just.of(30)))
//=> Just 35
// Crocks' `ap`
console.log(C.ap(add5)(Just.of(35)))
//=> Error ap: Both arguments must be Applys of the same type |
You could choose to pin the version when you add fantasy-land as a dependency. That way you can choose to support a specific version of fantasy-land, and if you don't agree with the direction in the future, just don't support that newer version and don't upgrade. I believe other libraries are doing something similar.
Ok sure, will track this! |
We would have to add "new" things ourselves and curate it anyway. So for instance, |
Describing the bug in terms of the implementation:
src/core/flNames.js
is missing theap
property.src/pointfree/ap.js
is calling hardcoded.ap
, instead of calling the fantasy-land method name, if available. See map.js for inspiration.To Reproduce
Expected output
Actual output
Possible solution
I implemented a quick hack to fix it:
Change
src/pointfree/ap.js:20
to:Add the
ap
property tosrc/core/flNames.js
:ap: 'fantasy-land/ap'
Actual solution
Instead of maintaining a list of fantasy-land names in
flNames.js
, why not add the npm package fantasy-land as a dependency? It actually exports this list of names. I bet more stuff is missing, or will be in the near future ;)The text was updated successfully, but these errors were encountered: