Skip to content
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

Presumptuous monadism #24

Open
stuartpb opened this issue Apr 28, 2017 · 6 comments
Open

Presumptuous monadism #24

stuartpb opened this issue Apr 28, 2017 · 6 comments

Comments

@stuartpb
Copy link

I passed this input to pointfree.io:

latterLetter1d alphabet letter = (elemIndex letter alphabet) `further` latter alphabet

This was the output:

latterLetter1d = ap (flip . (further .) . flip elemIndex) latter

Is there no pointfree way to express this without importing Control.Monad? Or, if monads are really the cleanest way to do this, is there a formulation of it without so many dots and flips (#23)?

@josephcsible
Copy link

josephcsible commented Dec 8, 2018

Is there no pointfree way to express this without importing Control.Monad?

Yes, ap is the same as <*> in this case, and the latter is in the Prelude:

latterLetter1d = flip . (further .) . flip elemIndex <*> latter

Or, if monads are really the cleanest way to do this, is there a formulation of it without so many dots and flips (#23)?

Yes:

latterLetter1d = flip (flip (liftM2 further) latter . elemIndex)

@bmillwood
Copy link
Owner

Nowadays I think you don't need to import Control.Monad to get these instances, so I don't think it's bad to use the monad interface here.

@josephcsible
Copy link

No, you still do need to import Control.Monad, even in GHC 8.8.1.

@josephcsible
Copy link

Hello?

@bmillwood
Copy link
Owner

oh, I misunderstood this at the time, sorry (just happened to revisit it now). The issue is not the instance itself, but the function ap.

Nevertheless, I don't personally feel excited to work on this. It seems like using standard base imports is often going to result in better code, so at most I'd want this to be an option, --prelude-only or something.

@bmillwood bmillwood reopened this Apr 23, 2023
@josephcsible
Copy link

It seems like using standard base imports is often going to result in better code

For other things like join and liftA2 I agree, but for ap in particular, is there ever a reason to use it rather than <*>?

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

No branches or pull requests

3 participants