<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="ltr" class="mw-geshi mw-content-ltr"><div class="haskell source-haskell"><pre class="de1">It seems this’s a very old request, see <a href="https://wiki.haskell.org/If-then-else" class="">https://wiki.haskell.org/If-then-else</a>. I’d like to see following:</pre><pre class="de1"><br class=""></pre><pre class="de1"><span class="st0">ifThenElse :: Bool -> a -> a -> a
ifThenElse</span> True x <span class="sy0">_</span> <span class="sy0">=</span> x
<span class="st0">ifThenElse False _ y = y</span></pre></div></div><div class=""><br class=""></div><div class=""><div dir="ltr" class="mw-geshi mw-content-ltr"><div class="haskell source-haskell"><pre class="de1"><span class="kw1">infixr</span> <span class="nu0">1</span> <span class="sy0">?</span>
<span class="br0">(</span><span class="sy0">?</span><span class="br0">)</span> <span class="sy0">::</span> <span class="kw4">Bool</span> <span class="sy0">-></span> a <span class="sy0">-></span> a <span class="sy0">-></span> a
<span class="br0">(</span><span class="sy0">?</span><span class="br0">)</span> <span class="sy0">=</span> ifThenElse</pre><div class=""><br class=""></div></div></div><div class=""><pre class="de1"><span class="kw1">in Date.Bool module, it will have advantages that:</span></pre><pre class="de1"><span class="kw1"><br class=""></span></pre><pre class="de1"><span class="kw1">+ It’s more composable than syntax. </span></pre><pre class="de1"><span class="kw1">+ Write (xxx ? yyy $ zzz) instead of (if xxx then yyy else zzz) is more consistent with (f . g $ x) style, and save key strokes.</span></pre><pre class="de1"><span class="kw1">+ In module with RebindableSyntax enabled, you can import </span>ifThenElse to get default behavior.</pre><pre class="de1"><br class=""></pre><pre class="de1">Whether or not to be exported by Prelude is another question, but Data.Bool seems a good place to start with.</pre><pre class="de1"><br class=""></pre><pre class="de1">Cheers~</pre><pre class="de1">Winter</pre></div></div></body></html>