GithubHelp home page GithubHelp logo

"ap" is backwards? about bow HOT 5 CLOSED

bow-swift avatar bow-swift commented on May 18, 2024
"ap" is backwards?

from bow.

Comments (5)

truizlop avatar truizlop commented on May 18, 2024

The definition of ap is done to keep consistency with the typeclass definition for Applicative, and the behavior of ap is not the same as in <*>. If we check the signature for both:

ap : (F<A>, F<(A) -> B>) -> F<B>
<*> : (F<A>, F<B>) -> F<(A) -> B>

<*> definition, and the usage you are proposing, is encoded in Bow as product in the Applicative typeclass, and the way you could be using it is:

Option<Int>.applicative().product(one, two).fix().map(add)

The syntax could be better but it is a matter of getting to the point where the language supports higher kinded types natively.

from bow.

stephencelis avatar stephencelis commented on May 18, 2024

It may be a language barrier thing, but you have me a bit confused. You don't have <*> defined at all in Bow, so there's no signature to compare your ap with. You've also mentioned deprecating operators, so I assume <*> isn't being added?

In Haskell, ap is on the Monad typeclass and is defined with the exact same infix way as <*> (though with different type class constraints):

ap :: m (a -> b) -> m a -> m b
<*> :: f (a -> b) -> f a -> f b

So is it fair to assume that you want Bow's type classes to be consistent with Arrow's? That can definitely be a project prerogative, though porting over a language limitation is unfortunate.

from bow.

truizlop avatar truizlop commented on May 18, 2024

Sorry, I think I misunderstood it on my first read. You are right; in fact, in Cats for Scala this is reversed as well. Since your approach is more readable in Swift, we can refactor it for the sake of the usability. Our aim is to maximize compatibility with Arrow, of course, but in some cases like this, a more Swiftier approach is preferrable. I'll add this to my pipeline and perform the change in the next few days.

from bow.

truizlop avatar truizlop commented on May 18, 2024

@stephencelis please, take a look at the changes in #80, addressing the improvement you suggested here.

from bow.

truizlop avatar truizlop commented on May 18, 2024

#80 is merged and this will be in the next release.

from bow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.