Skip to content

Add generalized flip #83

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

Merged
merged 3 commits into from
Sep 14, 2016
Merged

Add generalized flip #83

merged 3 commits into from
Sep 14, 2016

Conversation

joneshf
Copy link
Member

@joneshf joneshf commented Jun 4, 2016

Closes #82

The name of this function along with its operator alias can change.
I don't know a better name for either and have no strong feelings.

The name of this function along with its operator alias can change.
I don't know a better name for either and have no strong feelings.
@texastoland
Copy link

texastoland commented Jun 4, 2016

Wow cool!

instance ff ::             Functor (a -> _)
flip        ::  a b c   .                     (a -> (b -> c)) -> b -> (a -> c)
flip'       ::    b c f . Functor  f       =>  f    (b -> c)  -> b ->  f    c
flip'       ::  a b c   . Functor (a -> _) =>  a -> (b -> c)  -> b -> (a -> c)

Do we need to keep the specialized version? Does it need an operator?

@paf31
Copy link
Contributor

paf31 commented Jun 4, 2016

Yes, we should keep the specialized (optimized) version, I think.

@texastoland
Copy link

texastoland commented Jun 4, 2016

That's going down the Haskell map versus fmap road. In that case call it fflip. Rather than naming conventions for specialized/default variants of functions there should a way to provide implementations in type classes (e.g. DefaultSignatures) or without (as in this case). But adding TIMTOWTDI seems undesirable.

@joneshf
Copy link
Member Author

joneshf commented Jun 5, 2016

Don't let the name flip' sway your judgement. const and pure live in harmony. compose and map live in harmony.

Call it some other name if that makes it easier to deal with. switch? surface? embed? It takes a function in some computational context and returns a function that stuffs the result in the computational context.

Again, I don't care the name, so use what you like best.

TIMTOWTDI

wat?

@michaelficarra
Copy link
Contributor

"There is more than one way to do it".

@texastoland
Copy link

texastoland commented Jun 5, 2016

const and pure live in harmony. compose and map live in harmony.

Excellent points. I still think it'd be better to address the user facing issue of specializing implementations than keep renaming things.

There is more than one way to do it.

(Perl) cf. There should be one—and preferably only one—obvious way to do it. (Python)

@paf31
Copy link
Contributor

paf31 commented Jun 5, 2016

"There is more than one way to do it".

This doesn't bother me so much.

@joneshf
Copy link
Member Author

joneshf commented Jun 24, 2016

What's the verdict here?

@texastoland
Copy link

Sounds like it just needs a name. I'd like any function to be able to be specialized but it's mostly unrelated.

@garyb
Copy link
Member

garyb commented Jun 24, 2016

fapply perhaps? Not a great name, but it's definitely closest in signature to apply, but only requires the Functor constraint. It seems more apply-y than flip-y to me anyway, even though when dealing with (->) a it is indeed flip.

@garyb
Copy link
Member

garyb commented Jun 24, 2016

flap? 😄

@garyb
Copy link
Member

garyb commented Jun 24, 2016

^ in all seriousness I do actually like flap, it doesn't really mean anything (useful for an abstract function), and if you try really hard I guess it kind works:

  1. it's part flip, part apply
  2. it takes a function in a context, opens a flap and throws a in

@texastoland
Copy link

texastoland commented Jun 24, 2016

It comes up in Hayoo but no solid convention.

@texastoland
Copy link

unapply? It also looks vaguely (less than apply) like unfoldr and sieve in Profunctor.

@paf31
Copy link
Contributor

paf31 commented Jun 24, 2016

To me, one of the most useful places for this function is alongside <$> and <*>, since you can use it to apply a function when one of the arguments is not wrapped in an f, without using pure.

So I suggest it should be called applied, with an infix alias of some kind.

@epost
Copy link

epost commented Jun 28, 2016

flap = abstract flip. I love it!

@joneshf
Copy link
Member Author

joneshf commented Jun 28, 2016

an infix alias of some kind.

One that comes to mind is (<@>). to pun off of @garyb, it's got an a inside a "flap":

it takes a function in a context, opens a flap and throws a in

😉

@joneshf
Copy link
Member Author

joneshf commented Jul 13, 2016

So, we're at flap and <@>. Bueno, or different name?

@paf31
Copy link
Contributor

paf31 commented Jul 13, 2016

Sounds good, thanks! Do the precedence levels work out so that this can be used with <*>?

@joneshf
Copy link
Member Author

joneshf commented Jul 13, 2016

Do you have an example of how you'd like it to parse?

@texastoland
Copy link

Perhaps it should be a test case?

@paf31
Copy link
Contributor

paf31 commented Jul 13, 2016

Something like threeve <$> Just 1 <@> 'a' <*> Just true I think.

@paf31
Copy link
Contributor

paf31 commented Jul 14, 2016

If the operator can be made to work like that, I think it would be nice to put something about it in the comment as well.

The new precedence lets the operator play nicely with others.
@joneshf
Copy link
Member Author

joneshf commented Aug 28, 2016

Updated. Didn't add a test since there's no precedent for what a ps test looks like here.

@paf31 paf31 merged commit a385de9 into purescript:master Sep 14, 2016
@paf31
Copy link
Contributor

paf31 commented Sep 14, 2016

Thanks, and sorry this took such a long time to merge!

@joneshf
Copy link
Member Author

joneshf commented Sep 14, 2016

No worries. Thanks for merging!

@joneshf joneshf deleted the functor-flip branch September 14, 2016 03:10
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.

6 participants