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

Add `&&^` and `||^` operators #97

Closed
chshersh opened this issue Oct 7, 2018 · 6 comments

Comments

Projects
4 participants
@chshersh
Copy link
Member

commented Oct 7, 2018

They are often useful. Also, they are somewhat common because names are unambiguous.

(&&^) :: Monad m => m Bool -> m Bool -> m Bool
(||^) :: Monad m => m Bool -> m Bool -> m Bool

@chshersh chshersh added this to To do in #2: Hacktoberfest (October, 2018) via automation Oct 7, 2018

@mukul2gautam

This comment has been minimized.

Copy link

commented Oct 7, 2018

(&&^) : : monad m => m Bool -> m Bool -> m Bool
(||^) : : monad m => m Bool -> m Bool -> m Bool

@kahlil29

This comment has been minimized.

Copy link
Member

commented Oct 7, 2018

Is this about using binding in a do notation and then getting the inner Bool values, applying the operator on it and then using pure again to return the final answer?

Or is there more to it?

@chshersh

This comment has been minimized.

Copy link
Member Author

commented Oct 8, 2018

@kahlil29 I think you can also use ifM function for that:

ifM :: Monad m => m Bool -> m a -> m a -> m a
ifM p x y = p >>= \b -> if b then x else y

@kahlil29

This comment has been minimized.

Copy link
Member

commented Oct 8, 2018

Thanks @chshersh I'll have a crack at it, then I'll ask for some feedback 😄

@cronokirby

This comment has been minimized.

Copy link
Collaborator

commented Oct 8, 2018

Why have Monad here instead of Applicative?

@chshersh

This comment has been minimized.

Copy link
Member Author

commented Oct 9, 2018

@cronokirby You can't achieve the following behavior with Applicative:

ghci> Just False &&^ undefined
Just False

Monadic version is lazier.

Jonathas-Conceicao added a commit to Jonathas-Conceicao/relude that referenced this issue Oct 11, 2018

Jonathas-Conceicao added a commit to Jonathas-Conceicao/relude that referenced this issue Oct 11, 2018

Jonathas-Conceicao added a commit to Jonathas-Conceicao/relude that referenced this issue Oct 11, 2018

@vrom911 vrom911 closed this in #101 Oct 12, 2018

#2: Hacktoberfest (October, 2018) automation moved this from To do to Done: Issues Oct 12, 2018

vrom911 added a commit that referenced this issue Oct 12, 2018

[#97] Added monadic version of (&&) and (||) operators (#101)
* [#97] Added monadic version of (&&) and (||) operators

* CHANGELOG update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.