Why does Haskell have a built-in if/then/else
, which is dependent on the Bool
type, instead of having a simple library function? Such as
if :: Bool -> a -> a -> a
if True x _ = x
if False _ y = y
haskell
Why does Haskell have a built-in if/then/else
, which is dependent on the Bool
type, instead of having a simple library function? Such as
if :: Bool -> a -> a -> a
if True x _ = x
if False _ y = y
Best Answer
It's purely for the nice sugar of the
if
,then
, andelse
keywords; in fact, GHC (with theRebindableSyntax
extension enabled) will desugar the syntax by simply calling whateverifThenElse
function is in scope.