-
Notifications
You must be signed in to change notification settings - Fork 376
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
Question about Applicatives #50
Comments
I guess I copied Haskell's It'd probably be more consistent to flip it (i.e. it would look more like other functors). What should we do about updating the specification? I have no hesitation to release new versions of my projects but does anyone have a project where they can't or don't want to change the order of |
I think this goes back to #24. However, we haven't really been keeping up with updating the version number to begin with. If you'd like I can go back to when version 0.0.1 was first "released" and look through the changes since then, tagging and whatever. Or we can just start right now with a set version, and keep everything semver'd from here on. |
There's an alternative definition of Applicatives that uses a "join" or "seq" operator instead of "ap".
It's equivalent to
And it even comes with equivalent laws:
The "ap"-based one seems to be the best in Haskell since functions are auto-curried and tuples are non-recursive. But in JS we can use heterogenous lists instead, so "join" might be more natural to express. In fantasyland, I guess it would be something like "a.join(functors)" is a functor of a combined array of results from the given functors. Anyways, slightly rambly, but this represents the way the |
related to #56, although |
looks really odd to me. Applying functions with multiple arguments doesn't seem to work well - or is quite ugly, if we look the linked example:
Not only is there much nesting, but also the order of the arguments is inverted. Having used The
It wouldn't be more consistent to flip it just because we have flipped |
In Parsimmon I've recently gone with the |
Yeah, this needs to be fixed. PR would be awesome! |
Should we flip the order of |
I'm having trouble typing class Stream<T> {
// Apply
ap<A,B>( other:Stream<A> ): Stream<B> {
// In order for .ap() to work `this` must be a `Stream<A => B>`,
// but I don't know how to express that constraint in Flow, so just use `any`
const streamF:BasicStream<any> = this.observe
return new Stream(bs.ap(streamF)(other.observe))
}
} Would be straightforward if it was other way around. |
That is quite unfortunate. Can you actually write the other way with flow? |
Sure, with reversed version of ap it will look like this: class Stream<T> {
ap<A>( other:Stream<( x:T ) => A> ): Stream<A> {
return new Stream(bs.ap(other.observe)(this.observe))
}
} |
For the record: not a big problem for me, just wanted to add my two cents :) |
I've been hit with this recently as well. So the question is how do we change it, because I think we should! Could we maybe rename |
We could certainly use NPM to help us manage changes like that after libraries start depending on FL. We could do for example:
Then libraries could specify appropriate versions range in their peerDependency to |
I'd rather have 3.0 out before 2.0 💃 |
No preference on that matter from me :) |
So you only want to change this because flow's type system is not sophisticatd enough? |
Yep, and also the fact that it's inconsistent with Feel free to discuss in the PR: #145 |
I think this can be closed now, no? |
Indeed it can! |
Sorry for commenting on closed issue, but It may help somebody dealing with the same issue as I did. I heavily use monet.js algebraic structures along with ramda. As @cwmyers pointed out, applicatives in monet.js are not compatible with fantasy-land spec. Though one cannot use ramda's |
@char0n looks like ramda#1900 was merged. So soon, very soon, once ramda releases its next version we should all be gtg!! |
@evilsoft I've just tried using I have one additional question regarding composition of Apply spec regarding const add3 = curry((a, b, c) => a + b + c);
const m10 = Maybe.Some(10);
const m15 = Maybe.Some(15);
const m17 = Maybe.Some(17);
m10.ap(m15.ap(m17.map(add3))) What is the eqvivalent of Update: |
Hi guys,
I've been implementing FantasyLand in monet.js and I've come a little unstuck with
ap()
.Unless I've got the wrong end of the stick FantasyLand's
ap()
demands that the applicative already contains a function and then accepts an applicative with a value.appWithFunction.ap(appWithValue)
Unfortunately I've followed scalaz & functional java approach which does the opposite.
appWithValue.ap(appWithFunction)
See here for the
Maybe
example: http://cwmyers.github.io/monet.js/#apmaybefnHere is an example from FunctionalJava
Option
:public final <B> Option<B> apply(Option<F<A,B>> of)
So my question is why has Fantasy Land taken this particular approach to applicative? I'm worried that this would be a large breaking change to the monet library and I'm trying to figure out what the right thing is to do.
Cheers,
Chris
The text was updated successfully, but these errors were encountered: