Add ifThenElse and (?) to Data.Bool

Joachim Breitner mail at joachim-breitner.de
Mon Nov 21 18:29:10 UTC 2016


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 at joachim-breitner.dehttps://www.joachim-breitner.de/
  XMPP: nomeata at joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F
  Debian Developer: nomeata at debian.org
-------------- 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: <http://mail.haskell.org/pipermail/libraries/attachments/20161121/11e439e4/attachment.sig>


More information about the Libraries mailing list