Add ifThenElse and (?) to Data.Bool

Joachim Breitner mail at
Mon Nov 21 18:29:10 UTC 2016


Am Donnerstag, den 17.11.2016, 10:43 +0800 schrieb winter:
> It seems this’s a very old request, see
> 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.


Joachim “nomeata” Breitner
  mail at joachim-breitner.de
  XMPP: nomeata at • OpenPGP-Key: 0xF0FBF51F
  Debian Developer: nomeata at
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <>

More information about the Libraries mailing list