Add ifThenElse and (?) to Data.Bool

It seems this’s a very old request, see https://wiki.haskell.org/If-then-else https://wiki.haskell.org/If-then-else. I’d like to see following: ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = x ifThenElse False _ y = y infixr 1 ? (?) :: Bool -> a -> a -> a (?) = ifThenElse in Date.Bool module, it will have advantages that: + It’s more composable than syntax. + Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes. + In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior. Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with. Cheers~ Winter

If ifThenElse is good for RebindableSyntax, then I'm +1 on that (but I've
never played with that extension, so I don't really know). I'm -1 on (?).
We already have bool, which tends to be rather more useful when partially
applied.
On Nov 16, 2016 9:43 PM, "winter"
It seems this’s a very old request, see https://wiki.haskell.org/If-then-else. I’d like to see following:
ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = xifThenElse False _ y = y
infixr 1 ?(?) :: Bool -> a -> a -> a(?) = ifThenElse
in Date.Bool module, it will have advantages that:
+ It’s more composable than syntax.
+ Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes.
+ In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior.
Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.
Cheers~
Winter
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

I’m totally aware of the existence of bool, i suppose (?) is mainly used in fully application to get a different style than if-then-else syntax, say, ... isGoo <- checkGoo isGoo ? goo $ woo ... But like what the wiki suggested, (?) can be used in some high-order situations. I like this operator because the mnemonic of questioning meaning.
On 17 Nov 2016, at 11:03, David Feuer
wrote: If ifThenElse is good for RebindableSyntax, then I'm +1 on that (but I've never played with that extension, so I don't really know). I'm -1 on (?). We already have bool, which tends to be rather more useful when partially applied.
On Nov 16, 2016 9:43 PM, "winter"
mailto:drkoster@qq.com> wrote: It seems this’s a very old request, see https://wiki.haskell.org/If-then-else https://wiki.haskell.org/If-then-else. I’d like to see following: ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = x ifThenElse False _ y = y
infixr 1 ? (?) :: Bool -> a -> a -> a (?) = ifThenElse
in Date.Bool module, it will have advantages that:
+ It’s more composable than syntax. + Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes. + In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior.
Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.
Cheers~ Winter
_______________________________________________ Libraries mailing list Libraries@haskell.org mailto:Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

And here’s some other stuff i can came up with it(without obscured readability IMHO): ... -- replacement for ifM in various package, similar to (>>= when) (mFlag >>= (?)) flagEnabled -- mFlag :: Monad m => m Bool $ flagDisabled -- nicer if-then-else in applicative style (?) <$> fFlag <$> flagEnabled <*> flagDisabled -- compose with predicates to define your own if ifLower = (?) . isLower ifLower ‘X’ lower upper ... Basically it's a good if-then-else replacement if you’re comfortable with point-free style.
On 17 Nov 2016, at 11:16, winter
wrote: I’m totally aware of the existence of bool, i suppose (?) is mainly used in fully application to get a different style than if-then-else syntax, say,
... isGoo <- checkGoo isGoo ? goo $ woo ...
But like what the wiki suggested, (?) can be used in some high-order situations. I like this operator because the mnemonic of questioning meaning.
On 17 Nov 2016, at 11:03, David Feuer
mailto:david.feuer@gmail.com> wrote: If ifThenElse is good for RebindableSyntax, then I'm +1 on that (but I've never played with that extension, so I don't really know). I'm -1 on (?). We already have bool, which tends to be rather more useful when partially applied.
On Nov 16, 2016 9:43 PM, "winter"
mailto:drkoster@qq.com> wrote: It seems this’s a very old request, see https://wiki.haskell.org/If-then-else https://wiki.haskell.org/If-then-else. I’d like to see following: ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = x ifThenElse False _ y = y
infixr 1 ? (?) :: Bool -> a -> a -> a (?) = ifThenElse
in Date.Bool module, it will have advantages that:
+ It’s more composable than syntax. + Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes. + In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior.
Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.
Cheers~ Winter
_______________________________________________ Libraries mailing list Libraries@haskell.org mailto:Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

(?) <$> fFlag <$> flagEnabled <*> flagDisabled
You probably don't want this. This performs both effects (!), regardless of
the flag, but only keeps one result.
-Edward
On Wed, Nov 16, 2016 at 11:01 PM, winter
And here’s some other stuff i can came up with it(without obscured readability IMHO):
... -- replacement for ifM in various package, similar to (>>= when)
(mFlag >>= (?)) flagEnabled -- mFlag :: Monad m => m Bool $ flagDisabled
-- nicer if-then-else in applicative style (?) <$> fFlag <$> flagEnabled <*> flagDisabled
-- compose with predicates to define your own if ifLower = (?) . isLower ifLower ‘X’ lower upper ...
Basically it's a good if-then-else replacement if you’re comfortable with point-free style.
On 17 Nov 2016, at 11:16, winter
wrote: I’m totally aware of the existence of bool, i suppose (?) is mainly used in fully application to get a different style than if-then-else syntax, say,
... isGoo <- checkGoo isGoo ? goo $ woo ...
But like what the wiki suggested, (?) can be used in some high-order situations. I like this operator because the mnemonic of questioning meaning.
On 17 Nov 2016, at 11:03, David Feuer
wrote: If ifThenElse is good for RebindableSyntax, then I'm +1 on that (but I've never played with that extension, so I don't really know). I'm -1 on (?). We already have bool, which tends to be rather more useful when partially applied.
On Nov 16, 2016 9:43 PM, "winter"
wrote: It seems this’s a very old request, see https://wiki.haskell.org/If-then-else. I’d like to see following:
ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = xifThenElse False _ y = y
infixr 1 ?(?) :: Bool -> a -> a -> a(?) = ifThenElse
in Date.Bool module, it will have advantages that:
+ It’s more composable than syntax.
+ Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes.
+ In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior.
Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.
Cheers~
Winter
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

Ah Yeah, i see. It’s indeed a rare use case. From all your feedback, I guess i will make a package with (?) for someone who want to save keystrokes like me ;) Cheers~ Winter
On 17 Nov 2016, at 12:03, Edward Kmett
wrote: (?) <$> fFlag <$> flagEnabled <*> flagDisabled
You probably don't want this. This performs both effects (!), regardless of the flag, but only keeps one result.
-Edward
On Wed, Nov 16, 2016 at 11:01 PM, winter
mailto:drkoster@qq.com> wrote: And here’s some other stuff i can came up with it(without obscured readability IMHO): ... -- replacement for ifM in various package, similar to (>>= when)
(mFlag >>= (?)) flagEnabled -- mFlag :: Monad m => m Bool $ flagDisabled
-- nicer if-then-else in applicative style (?) <$> fFlag <$> flagEnabled <*> flagDisabled
-- compose with predicates to define your own if ifLower = (?) . isLower ifLower ‘X’ lower upper ...
Basically it's a good if-then-else replacement if you’re comfortable with point-free style.
On 17 Nov 2016, at 11:16, winter
mailto:drkoster@qq.com> wrote: I’m totally aware of the existence of bool, i suppose (?) is mainly used in fully application to get a different style than if-then-else syntax, say,
... isGoo <- checkGoo isGoo ? goo $ woo ...
But like what the wiki suggested, (?) can be used in some high-order situations. I like this operator because the mnemonic of questioning meaning.
On 17 Nov 2016, at 11:03, David Feuer
mailto:david.feuer@gmail.com> wrote: If ifThenElse is good for RebindableSyntax, then I'm +1 on that (but I've never played with that extension, so I don't really know). I'm -1 on (?). We already have bool, which tends to be rather more useful when partially applied.
On Nov 16, 2016 9:43 PM, "winter"
mailto:drkoster@qq.com> wrote: It seems this’s a very old request, see https://wiki.haskell.org/If-then-else https://wiki.haskell.org/If-then-else. I’d like to see following: ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = x ifThenElse False _ y = y
infixr 1 ? (?) :: Bool -> a -> a -> a (?) = ifThenElse
in Date.Bool module, it will have advantages that:
+ It’s more composable than syntax. + Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes. + In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior.
Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.
Cheers~ Winter
_______________________________________________ Libraries mailing list Libraries@haskell.org mailto:Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org mailto:Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

On Thu, 17 Nov 2016, winter wrote:
Ah Yeah, i see. It’s indeed a rare use case. From all your feedback, I guess i will make a package with (?) for someone who want to save keystrokes like me ;)
I use if' and (?:) from https://hackage.haskell.org/package/utility-ht-0.0.12/docs/Data-Bool-HT.html E.g. this is very handy: if' (even n) "even" $ if' (isPrime n) "prime" $ "boring" (?:) is the uncurried variant of (?). I do not see value in curried (?) because I can just use `if'` then (which I never did).

Could we use `bool` rather than add a new term for RebindableSyntax? i.e. define if-then-else in terms of `bool`.

If this rebindable syntax is about what I think it is, that would seem
strange. bool is the Bool eliminator. It would seem weird to give it a type
like, say,
bool :: Monad m => m a -> m a -> m Bool -> m a
On Nov 16, 2016 10:06 PM, "M Farkas-Dyck"
Could we use `bool` rather than add a new term for RebindableSyntax? i.e. define if-then-else in terms of `bool`. _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

I'm -0.5 on ifThenElse (if it can be used with RebindableSyntax then
someone may want to use it, though I personally find the bool function
to be more than sufficient as I tend to find the "which branch do I
choose" argument to be the last when constructing function pipelines),
and -1 for the operator.
On 17 November 2016 at 13:43, winter
It seems this’s a very old request, see https://wiki.haskell.org/If-then-else. I’d like to see following:
ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = x ifThenElse False _ y = y
infixr 1 ? (?) :: Bool -> a -> a -> a (?) = ifThenElse
in Date.Bool module, it will have advantages that:
+ It’s more composable than syntax.
+ Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes.
+ In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior.
Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.
Cheers~
Winter
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

I'm pretty strongly -1 on adding (?). It is one of the few single character
operators available to the average user out of the box and this is a space
where we already have established combinators. It is a valuable portion of
the namespace to spend and each approach we offer means more inessential
complexity to newcomers to the language.
Given the existence of bool today I'm weakly -1 on ifThenElse. That said,
if we were to add RebindableSyntax support for it, I think that I'd
personally flip around to being in favor. It is a much more clear thing for
RebindableSyntax to call out to than something called "bool" that comes
with a different argument order.
These are just my personal feelings on the matter, and not any sort of
"cast in stone" CLC judgments.
-Edward
On Wed, Nov 16, 2016 at 9:43 PM, winter
It seems this’s a very old request, see https://wiki.haskell.org/If-then-else. I’d like to see following:
ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = xifThenElse False _ y = y
infixr 1 ?(?) :: Bool -> a -> a -> a(?) = ifThenElse
in Date.Bool module, it will have advantages that:
+ It’s more composable than syntax.
+ Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes.
+ In module with RebindableSyntax enabled, you can import ifThenElse to get default behavior.
Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.
Cheers~
Winter
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

Edward Kmett wrote:
I'm pretty strongly -1 on adding (?)... we already have established combinators... more inessential complexity to newcomers to the language.
I'm not so worried about that if it's not in the Prelude. I doubt that this would get wide usage. And if it does, then maybe that is better use of the namespace real estate. I am 0 on (?). I probably would never use it. I am -1 on ifThenElse. We already have bool. Some of our developers use it all the time and it's fine. It's not like "map" and "for" which have common idioms where parameter order really matters. Other than that, we shouldn't litter the libraries with flipped versions of everything. Anyway, bool is the natural parameter order in Haskell. I'll make more explicit what others have already said, with this analogy: maybe (if it fails) (if it succeeds) (input data) either (if it fails) (if it succeeds) (input data) foldl (if it's null) (if it's not null) (input data) foldr (if it's null) (if it's not null) (input data) Whereas Haskell's if-then-else syntax is awkward. Some people (not me) even say it should never be used at all. And so bool (if it fails) (if it succeeds) (input data) makes the most sense. -Yitz

On Thu, 17 Nov 2016, Yitzchak Gale wrote:
Anyway, bool is the natural parameter order in Haskell. I'll make more explicit what others have already said, with this analogy:
maybe (if it fails) (if it succeeds) (input data) either (if it fails) (if it succeeds) (input data)
foldl (if it's null) (if it's not null) (input data) foldr (if it's null) (if it's not null) (input data)
Unfortunately, it is the other way round: foldl (if it's not null) (if it's null) (input data) foldr (if it's not null) (if it's null) (input data)

I decide to make a standalone package: http://hackage.haskell.org/package/if http://hackage.haskell.org/package/if Cheers! Winter
On 17 Nov 2016, at 18:19, Henning Thielemann
wrote: On Thu, 17 Nov 2016, Yitzchak Gale wrote:
Anyway, bool is the natural parameter order in Haskell. I'll make more explicit what others have already said, with this analogy:
maybe (if it fails) (if it succeeds) (input data) either (if it fails) (if it succeeds) (input data)
foldl (if it's null) (if it's not null) (input data) foldr (if it's null) (if it's not null) (input data)
Unfortunately, it is the other way round:
foldl (if it's not null) (if it's null) (input data) foldr (if it's not null) (if it's null) (input data) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

FWIW, Winter, I sorta like that operator and it is even readable to people
who use C, JS, etc. Thanks for the library. :)
ᐧ
On Thu, Nov 17, 2016 at 7:19 AM, winter
I decide to make a standalone package: http://hackage. haskell.org/package/if
Cheers! Winter
On 17 Nov 2016, at 18:19, Henning Thielemann < lemming@henning-thielemann.de> wrote:
On Thu, 17 Nov 2016, Yitzchak Gale wrote:
Anyway, bool is the natural parameter order in Haskell. I'll make more explicit what others have already said, with this analogy:
maybe (if it fails) (if it succeeds) (input data) either (if it fails) (if it succeeds) (input data)
foldl (if it's null) (if it's not null) (input data) foldr (if it's null) (if it's not null) (input data)
Unfortunately, it is the other way round:
foldl (if it's not null) (if it's null) (input data) foldr (if it's not null) (if it's null) (input data) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

Hi, Am Donnerstag, den 17.11.2016, 10:43 +0800 schrieb winter:
It seems this’s a very old request, see https://wiki.haskell.org/If-t hen-else. I’d like to see following:
ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = x ifThenElse False _ y = y
+1 on that. It is strange that GHC desugars to ifThenElse¹ without this function being available anywhere. Most (all?) of the other rebindable syntax elements work out of the box as before with Prelude imported but this one. Therefore, I’d support a proposal to add ifThenElse to the prelude. It would also make teaching nicer, by pointing students to this function and saying „if then else is just syntactic sugar for it“. Slightly better than „if then else is just syntactic sugar for a hypothetical function that you can define, but that is not there.“
infixr 1 ? (?) :: Bool -> a -> a -> a (?) = ifThenElse
-1. Operators are just too scarce. Greetings, Joachim ¹ http://downloads.haskell.org/~ghc/8.0.1/docs/html/users_guide/glasgow _exts.html#rebindable-syntax-and-the-implicit-prelude-import -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

On Mon, 21 Nov 2016, Joachim Breitner wrote:
It would also make teaching nicer, by pointing students to this function and saying „if then else is just syntactic sugar for it“. Slightly better than „if then else is just syntactic sugar for a hypothetical function that you can define, but that is not there.“
One implementation is there: http://hackage.haskell.org/package/utility-ht-0.0.12/docs/Data-Bool-HT.html#... if you want to point the students somewhere. :-)
participants (9)
-
David Feuer
-
Edward Kmett
-
Elliot Cameron
-
Henning Thielemann
-
Ivan Lazar Miljenovic
-
Joachim Breitner
-
M Farkas-Dyck
-
winter
-
Yitzchak Gale