Sitelet https://github.com/purescript/purescript-parallel/pull/20
Skip to content

Add parallel apply - #20

Merged
paf31 merged 3 commits into
purescript:masterfrom
LukaJCB:master
Sep 10, 2017
Merged

paf31 merged 3 commits into
purescript:masterfrom
LukaJCB:master

Conversation

@LukaJCB

@LukaJCB LukaJCB commented Aug 24, 2017

Copy link
Copy Markdown
Contributor

Adds a new function and operator (open for bike shedding on a more fitting operator) for parallel application. Would allow us to write:

Tuple <$> (Ajax.get "https://foo.com") <!> (Ajax.get "https://bar.com")

instead of:

sequential $
    Tuple <$> parallel (Ajax.get "https://foo.com")
          <*> parallel (Ajax.get "https://bar.com")

Comment thread src/Control/Parallel.purs Outdated
=> m (a -> b)
-> m a
-> m b
parApply mf ma = apply (parallel mf) (parallel ma) # sequential

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use parens rather than (#) here.

Comment thread src/Control/Parallel.purs
import Data.Foldable (class Foldable, traverse_, oneOfMap)
import Data.Traversable (class Traversable, traverse)

parApply

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a comment?

Comment thread src/Control/Parallel.purs Outdated
-> m b
parApply mf ma = apply (parallel mf) (parallel ma) # sequential

infixl 4 apply as <!>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This choice of name seems a bit arbitrary. Now, I'll admit, it's no more arbitrary than <*> or the recently added <@>, but I wonder if we need it at all. I might even just use parApply as an infix function if I need this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's pretty arbitrary. Personally I feel that an operator would provide a lot of value, but I'm ready to just define that in my own projects as an alias, if we choose not to include this :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not claim this name in a core library for something which the user can alias themselves.

@garyb

garyb commented Aug 24, 2017

Copy link
Copy Markdown
Member

Another option would be to include a newtype for things that are Parallel where <*> becomes parApply perhaps?

We basically had that before, but before there was a class... or something. I forget now.

@paf31

paf31 commented Aug 24, 2017

Copy link
Copy Markdown
Contributor

Well, the functional dependency implements the type function that gives you the applicative you want, it's just not a newtype necessarily.

@LukaJCB

LukaJCB commented Sep 10, 2017

Copy link
Copy Markdown
Contributor Author

So how would you like to move forward with this? :)

@paf31

paf31 commented Sep 10, 2017

Copy link
Copy Markdown
Contributor

If you could remove the operator for now, I'll merge this. Thanks!

@paf31

paf31 commented Sep 10, 2017

Copy link
Copy Markdown
Contributor

Thanks!

@paf31
paf31 merged commit c94818a into purescript:master Sep 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants