Code Monkey home page Code Monkey logo

Comments (4)

garyb avatar garyb commented on July 30, 2024

Oops, sorry, I meant to undo this change actually. I was intending to copy everything exactly as it is so as not to introduce new problems, and then we could discuss changes like this one.

Feel free to change it back, you should have commit access to all these library repos.

By the sounds of it we should just wait for default implementations before moving zipWithA. I kind of like the idea of having a zipWith in traversable, as then it could take a t a rather than [a]... but Traversable doesn't have a specific order if I remember rightly?

from purescript-control.

paf31 avatar paf31 commented on July 30, 2024

It seems like Data.Traversable would be a good place to put zipWithA until we think about implementing defaults, no?

from purescript-control.

joneshf avatar joneshf commented on July 30, 2024

Feel free to change it back, you should have commit access to all these library repos.

Nice!

Thinking about it, zipWith is really just a special case of <*> for Array (maybe others?). We should be able to implement an instance for Array that favors zipping, not combinations, so it shouldn't even be needed except to save transforming into and out of the other instance.

newtype ZipArray a = ZipArray [a]

instance Functor ZipArray where
    fmap f (ZipArray xs) = ZipArray (fmap f xs)

instance Applicative ZipArray where
    pure = ZipArray . repeat

    (ZipArray fs) <*> (ZipArray xs) = ZipArray (go fs xs)
        where
        go (g:gs) (y:ys) = g y : go gs ys
        go _      _      = []

Then we could do things like:

(+1) <$> ZipArray [1,2,3]

and we have the same semantics as normal Array

Or use the Applicative to do

(+) <$> ZipArray [1,2,3] <*> pure 1

And have it act like zipWith. Of course this generalizes to arbitrary arity functions like all Applicatives. In other words,

zipWith f xs ys = fromZipArray (f <$> toZipArray xs <*> toZipArray ys)

Or something.

So it should ultimately stay in Control.Applicative or be part of the Data.Array family (which seems more intuitive) once things are all done.

from purescript-control.

garyb avatar garyb commented on July 30, 2024

Closing this as I guess we must have figured it out at some point in the last year 😉

from purescript-control.

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.